Exercise 3.1: Deploy a New Application
mkdir ~/app1 && cd ~/app1cat <<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 }cat date.outcat <<EOF >> Dockerfile FROM python:3 ADD simple.py / ## RUN pip install pystrich CMD [ "python", "./simple.py" ] EOF{ 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 imagessudo podman run -it localhost/simpleappsudo find / -name date.out
Last updated