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.py
Open and add the following code:
print("Hello, World from Dockerized Python App!")
Check the file:
cat helloworld.py
Run it locally to test:
python3 --version
python3 helloworld.py
touch Dockerfile
Edit and add the following content:
# Use official Python base image
FROM python:3.12-slim
# Set working directory
WORKDIR /app
# Copy local code to the container
COPY helloworld.py .
# Command to run the app
CMD ["python", "helloworld.py"]
Check files:
ls
docker build -t atuljkamble/pythonhelloworld .
Check Docker images:
docker images
docker push atuljkamble/pythonhelloworld
docker pull atuljkamble/pythonhelloworld
docker run atuljkamble/pythonhelloworld
Check running containers:
docker container ls
docker ps -a
Hello, World from Dockerized Python App!
-
Make sure you are logged in to Docker Hub before pushing:
docker login
-
Replace
atuljkamble
with your Docker Hub username if different.
Atul Kamble