2020-03-26 04:41:17 +00:00
|
|
|
|
## Compose sample application
|
2020-04-08 14:39:04 +00:00
|
|
|
|
### Python/Flask application
|
2020-03-26 04:41:17 +00:00
|
|
|
|
|
|
|
|
|
Project structure:
|
|
|
|
|
```
|
|
|
|
|
.
|
2022-05-10 09:59:25 +00:00
|
|
|
|
├── compose.yaml
|
2020-03-26 04:41:17 +00:00
|
|
|
|
├── app
|
|
|
|
|
├── Dockerfile
|
|
|
|
|
├── requirements.txt
|
|
|
|
|
└── app.py
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
2022-05-10 09:59:25 +00:00
|
|
|
|
[_compose.yaml_](compose.yaml)
|
2020-03-26 04:41:17 +00:00
|
|
|
|
```
|
|
|
|
|
services:
|
|
|
|
|
web:
|
2022-07-08 13:22:59 +00:00
|
|
|
|
build:
|
|
|
|
|
context: app
|
|
|
|
|
target: builder
|
2020-03-26 04:41:17 +00:00
|
|
|
|
ports:
|
2022-07-08 13:22:59 +00:00
|
|
|
|
- '8000:8000'
|
2020-03-26 04:41:17 +00:00
|
|
|
|
```
|
|
|
|
|
|
2022-05-10 09:59:25 +00:00
|
|
|
|
## Deploy with docker compose
|
2020-03-26 04:41:17 +00:00
|
|
|
|
|
|
|
|
|
```
|
2022-05-10 09:59:25 +00:00
|
|
|
|
$ docker compose up -d
|
2022-07-08 13:22:59 +00: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 04:41:17 +00:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Expected result
|
|
|
|
|
|
2020-07-28 03:22:17 +00:00
|
|
|
|
Listing containers must show one container running and the port mapping as below:
|
2020-03-26 04:41:17 +00:00
|
|
|
|
```
|
2022-07-08 13:22:59 +00: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 04:41:17 +00:00
|
|
|
|
```
|
|
|
|
|
|
2022-07-08 13:22:59 +00:00
|
|
|
|
After the application starts, navigate to `http://localhost:8000` in your web browser or run:
|
2020-03-26 04:41:17 +00:00
|
|
|
|
```
|
2022-07-08 13:22:59 +00:00
|
|
|
|
$ curl localhost:8000
|
2020-03-26 04:41:17 +00:00
|
|
|
|
Hello World!
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Stop and remove the containers
|
|
|
|
|
```
|
2022-05-10 09:59:25 +00:00
|
|
|
|
$ docker compose down
|
2020-03-26 04:41:17 +00:00
|
|
|
|
```
|
2022-07-08 13:22:59 +00:00
|
|
|
|
|
|
|
|
|
## Use with Docker Development Environments
|
|
|
|
|
|
|
|
|
|
You can use this sample with the Dev Environments feature of Docker Desktop.
|
|
|
|
|
|
|
|
|
|
![Screenshot of creating a Dev Environment in Docker Desktop](../dev-envs.png)
|
|
|
|
|
|
|
|
|
|
To develop directly on the services inside containers, use the HTTPS Git url of the sample:
|
|
|
|
|
```
|
|
|
|
|
https://github.com/docker/awesome-compose/tree/master/flask
|
|
|
|
|
```
|