A minimal Python web app, built with Flask, that listens on a port and prints a message to the console every time it's accessed. Created as a Docker exercise: it demonstrates how to package and run a Python app inside a Docker container.
containerized-python-app/
├── app.py
├── requirements.txt
├── Dockerfile
├── .dockerignore
└── README.md
| File | Purpose |
|---|---|
app.py |
The Flask app. |
requirements.txt |
Python dependencies. |
Dockerfile |
Defines how to build the Docker image. |
.dockerignore |
Excludes unnecessary files from the image. |
Build the image:
docker build . -t yourname
Run it:
docker run --rm -p 8080:8080 yourname
Then open your browser (or run curl) at:
http://localhost:8080
Each time the page is accessed, the app prints a message to the container logs
(docker logs <container>) and returns the same message in the response.
python3 -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txt
python app.py
Then open http://localhost:8080.