Docker makes it easy to package and run your apps anywhere — no more “it works on my machine.” In this post, we’ll go through the Docker workflow step by step, building a small Python app, running it in a container, and understanding how everything fits together.
Step 1 — Install Docker
Before we start, you need Docker installed on your machine.
- Windows / macOS: Install Docker Desktop
Follow the installer and make sure Docker is running (you’ll see a whale icon in your tray). - Linux: Install using your package manager. For example, on Ubuntu:
sudo apt update
sudo apt install docker.io
sudo systemctl start docker
sudo systemctl enable docker
Then verify it works:
docker --version
If you see a version number, you’re ready to go ✅
Step 2 — Create a Simple Python App
Let’s make a small Flask web app.
Create a new folder for your project:
mkdir docker-flask-demo
cd docker-flask-demo
Now create a file called app.py:
from flask import Flask
app = Flask(__name__)
@app.route("/")
def home():
return "Hello from Docker!"
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)
Then create a requirements.txt file:
flask
This file tells Docker which Python packages your app needs.
Step 3 — Create a Dockerfile
In the same folder, create a new file called Dockerfile (no extension):
# Use an official Python base image
FROM python:3.11-slim
# Set the working directory
WORKDIR /app
# Copy files into the container
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
# Run the app
CMD ["python", "app.py"]
This file is like a recipe — it tells Docker how to build your app.
Step 4 — Build the Docker Image
Now that you have a Dockerfile, let’s build the image.
Run this command in the same folder:
docker build -t my-flask-app .
-t my-flask-appgives your image a name..means “build using the Dockerfile in the current folder.”
Step 5 — Run the Container
Start your container:
docker run -p 5000:5000 my-flask-app
-p 5000:5000maps your computer’s port 5000 to the container’s port 5000.my-flask-appis the image you just built.
Now open http://localhost:5000 in your browser.
You should see:
“Hello from Docker!”
🎉 Congratulations — your Python app is running in Docker!
Step 6 — Update and Rebuild
If you change your app (for example, the message in app.py), you’ll need to rebuild the image:
docker build -t my-flask-app .
Then re-run it:
docker run -p 5000:5000 my-flask-app
💡 Pro tip: You can automate this with Docker Compose (we’ll cover that in a future post).
Step 7 — Share Your App (Optional)
You can share your app with anyone using Docker Hub.
- Log in:
docker login - Tag your image:
docker tag my-flask-app yourname/my-flask-app:latest - Push it:
docker push yourname/my-flask-app:latest
Now anyone can run your app with:
docker run -p 5000:5000 yourname/my-flask-app
Step 8 — Clean Up
When you’re done, you can stop and remove containers:
docker ps -a # list containers
docker stop <id> # stop one
docker rm <id> # remove it
docker image prune # delete old images
🧠 Step 9 — Recap
Let’s recap the Docker workflow:
- Write your app (
app.py) - Define dependencies (
requirements.txt) - Write a
Dockerfile - Build your image
- Run a container
- Rebuild and rerun as you update
- (Optional) Push to Docker Hub
That’s the core Docker workflow — build → run → share.