Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 52 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,69 @@
# python-flask-docker
# lvthillo/python-flask-docker

Basic Python Flask app in Docker which prints the hostname and IP of the container

### Build application
Build the Docker image manually by cloning the Git repo.
[![Docker Pulls](https://img.shields.io/docker/pulls/lvthillo/python-flask-docker)](https://hub.docker.com/r/lvthillo/python-flask-docker)
[![License](https://img.shields.io/github/license/lvthillo/python-flask-docker)](LICENSE)
[![GitHub stars](https://img.shields.io/github/stars/lvthillo/python-flask-docker)](https://github.com/lvthillo/python-flask-docker/stargazers)

## About

Launches a Flask web server inside a Docker container. When you visit the page, it displays:

```
$ git clone https://github.com/lvthillo/python-flask-docker.git
$ docker build -t lvthillo/python-flask-docker .
The hostname of the container is 6095273a4e9b and its IP is 172.17.0.2.
```

### Download precreated image
You can also just download the existing image from [DockerHub](https://hub.docker.com/r/lvthillo/python-flask-docker/).
```
This confirms the container is running and shows key networking info -- useful for demos, testing, and learning Docker networking.

## Quick Start

### Prerequisites
- [Docker](https://docs.docker.com/get-docker/) installed

### Option 1: Pull from Docker Hub (fastest)
```bash
docker pull lvthillo/python-flask-docker
docker run -d -p 8080:8080 --name flask-demo lvthillo/python-flask-docker
```
Visit http://localhost:8080

### Run the container
Create a container from the image.
### Option 2: Build from source
```bash
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
```
$ docker run --name my-container -d -p 8080:8080 lvthillo/python-flask-docker

## Verify It's Running
```bash
# 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-demo
```

Now visit http://localhost:8080
## Project Structure
```
The hostname of the container is 6095273a4e9b and its IP is 172.17.0.2.
python-flask-docker/
β”œβ”€β”€ src/
β”‚ └── app.py # Flask application
β”œβ”€β”€ Dockerfile # Docker build instructions
β”œβ”€β”€ requirements.txt # Python dependencies
└── README.md
```

### Verify the running container
Verify by checking the container ip and hostname (ID):
```
$ docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' my-container
172.17.0.2
$ docker inspect -f '{{ .Config.Hostname }}' my-container
6095273a4e9b
## Stop & Clean Up
```bash
docker stop flask-demo
docker rm flask-demo
```

## License

MIT