2020-03-26 08:41:17 +04:00
## Compose sample application
2022-09-01 11:39:33 -05:00
### Use with Docker Development Environments
You can open this sample in the Dev Environments feature of Docker Desktop version 4.12 or later.
[Open in Docker Dev Environments <img src="../open_in_new.svg" alt="Open in Docker Dev Environments" align="top"/> ](https://open.docker.com/dashboard/dev-envs?url=https://github.com/docker/awesome-compose/tree/master/flask )
2020-04-08 18:39:04 +04:00
### Python/Flask application
2020-03-26 08:41:17 +04:00
Project structure:
```
.
2022-05-10 11:59:25 +02:00
├── compose.yaml
2020-03-26 08:41:17 +04:00
├── app
├── Dockerfile
├── requirements.txt
└── app.py
```
2022-05-10 11:59:25 +02:00
[_compose.yaml_ ](compose.yaml )
2020-03-26 08:41:17 +04:00
```
services:
web:
2022-07-08 09:22:59 -04:00
build:
context: app
target: builder
2020-03-26 08:41:17 +04:00
ports:
2022-07-08 09:22:59 -04:00
- '8000:8000'
2020-03-26 08:41:17 +04:00
```
2022-05-10 11:59:25 +02:00
## Deploy with docker compose
2020-03-26 08:41:17 +04:00
```
2022-05-10 11:59:25 +02:00
$ docker compose up -d
2022-07-08 09:22:59 -04:00
[+] Building 1.1s (16/16) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
... 0.0s
=> => naming to docker.io/library/flask_web 0.0s
[+] Running 2/2
⠿ Network flask_default Created 0.0s
⠿ Container flask-web-1 Started
2020-03-26 08:41:17 +04:00
```
## Expected result
2020-07-27 22:22:17 -05:00
Listing containers must show one container running and the port mapping as below:
2020-03-26 08:41:17 +04:00
```
2022-07-08 09:22:59 -04:00
$ docker compose ps
NAME COMMAND SERVICE STATUS PORTS
flask-web-1 "python3 app.py" web running 0.0.0.0:8000->8000/tcp
2020-03-26 08:41:17 +04:00
```
2022-07-08 09:22:59 -04:00
After the application starts, navigate to `http://localhost:8000` in your web browser or run:
2020-03-26 08:41:17 +04:00
```
2022-07-08 09:22:59 -04:00
$ curl localhost:8000
2020-03-26 08:41:17 +04:00
Hello World!
```
Stop and remove the containers
```
2022-05-10 11:59:25 +02:00
$ docker compose down
2020-03-26 08:41:17 +04:00
```