Exercise 3.1: Deploy a New Application
애플리케이션 소스코드를 저장할 디렉토리를 생성하고 해당 디렉토리로 이동
mkdir ~/app1 && cd ~/app1파이썬 코드 생성
cat <<EOF > simple.py #!/usr/bin/python3 ## Import the necessary modules import time import socket ## Use an ongoing while loop to generate output while True : ## Set the hostname and the current date host = socket.gethostname() date = time.strftime("%Y-%m-%d %H:%M:%S") ## Convert the date output to a string now = str(date) ## Open the file named date in append mode ## Append the output of hostname and time print("Writing..") f = open("date.out", "a" ) f.write(host + ": " + now + "\n") f.close() ## Sleep for five seconds then continue the loop time.sleep(5) EOF파이썬 코드 실행
{ chmod +x simple.py ./simple.py }실행중인 파이썬 코드 정지 (Ctrl-C)
애플리케이션 로그 확인
cat date.outDockerfile 생성
cat <<EOF >> Dockerfile FROM python:3 ADD simple.py / ## RUN pip install pystrich CMD [ "python", "./simple.py" ] EOFPodman 설치
{ curl -fsSL -o podman-linux-amd64.tar.gz https://github.com/mgoltzsche/podman-static/releases/latest/download/podman-linux-amd64.tar.gz tar -xf podman-linux-amd64.tar.gz sudo cp -r podman-linux-amd64/usr podman-linux-amd64/etc / }컨테이너 이미지 생성
sudo podman build -t simpleapp .해당 노드에 있는 컨테이너 이미지 목록 확인
sudo podman images위에서 생성한 컨테이너 이미지 실행
sudo podman run -it localhost/simpleapp실행중인 컨테이너 정지 (Ctrl-C)
컨테이너 안에 저장된 애플리케이션 로그 파일 경로 확인
sudo find / -name date.out애플리케이션 로그 파일 확인
Last updated