Basic Python Flask app in Docker which prints the hostname and IP of the container
Launches a Flask web server inside a Docker container. When you visit the page, it displays:
The hostname of the container is 6095273a4e9b and its IP is 172.17.0.2.
This confirms the container is running and shows key networking info -- useful for demos, testing, and learning Docker networking.
- Docker installed
docker pull lvthillo/python-flask-docker
docker run -d -p 8080:8080 --name flask-demo lvthillo/python-flask-dockerVisit http://localhost:8080
git clone https://github.com/lvthillo/python-flask-docker.git
cd python-flask-docker
docker build -t lvthillo/python-flask-docker .
docker run -d -p 8080:8080 --name flask-demo lvthillo/python-flask-docker# Check container IP
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' flask-demo
# Check container hostname
docker inspect -f '{{ .Config.Hostname }}' flask-demo
# View logs
docker logs flask-demopython-flask-docker/
├── src/
│ └── app.py # Flask application
├── Dockerfile # Docker build instructions
├── requirements.txt # Python dependencies
└── README.md
docker stop flask-demo
docker rm flask-demoMIT