This guide will walk you through creating a simple Python Hello World app, containerizing it with Docker, and running it locally.
git clone https://github.com/atulkamble/pythonhelloworld.git
cd pythonhelloworld
.
├── Dockerfile
└── helloworld.py
touch helloworld.pyOpen and add the following code:
print("Hello, World")Check the file:
cat helloworld.pyRun it locally to test:
python helloworld.pytouch DockerfileEdit and add the following content:
FROM python:latest
WORKDIR /app
COPY helloworld.py .
CMD ["python", "helloworld.py"]Check files:
lsdocker build -t docker.io/atuljkamble/pythonhelloworld .Check Docker images:
docker imagesdocker push docker.io/atuljkamble/pythonhelloworlddocker pull docker.io/atuljkamble/pythonhelloworlddocker run docker.io/atuljkamble/pythonhelloworldCheck running containers:
docker container ls
docker ps -aHello, World from Dockerized Python App!
-
Make sure you are logged in to Docker Hub before pushing:
docker login
-
Replace
atuljkamblewith your Docker Hub username if different.
Atul Kamble