2021-10-10 21:38:34 +00:00
|
|
|
|
## Compose sample application
|
|
|
|
|
### Python/FastAPI application
|
|
|
|
|
|
|
|
|
|
Project structure:
|
|
|
|
|
```
|
2022-05-10 09:59:25 +00:00
|
|
|
|
├── compose.yaml
|
2021-10-10 21:38:34 +00:00
|
|
|
|
├── Dockerfile
|
|
|
|
|
├── requirements.txt
|
|
|
|
|
├── app
|
|
|
|
|
├── main.py
|
|
|
|
|
├── __init__.py
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
2022-05-10 09:59:25 +00:00
|
|
|
|
[_compose.yaml_](compose.yaml)
|
2021-10-10 21:38:34 +00:00
|
|
|
|
```
|
|
|
|
|
services:
|
|
|
|
|
api:
|
|
|
|
|
build: .
|
|
|
|
|
container_name: fastapi-application
|
|
|
|
|
environment:
|
|
|
|
|
PORT: 8000
|
|
|
|
|
ports:
|
|
|
|
|
- '8000:8000'
|
|
|
|
|
restart: "no"
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
2022-05-10 09:59:25 +00:00
|
|
|
|
## Deploy with docker compose
|
2021-10-10 21:38:34 +00:00
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
docker-compose up -d --build
|
|
|
|
|
```
|
|
|
|
|
## Expected result
|
|
|
|
|
|
|
|
|
|
Listing containers must show one container running and the port mapping as below:
|
|
|
|
|
```
|
|
|
|
|
$ docker ps
|
|
|
|
|
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
|
|
|
|
7087a6e79610 5c1778a60cf8 "/start.sh" About a minute ago Up About a minute 80/tcp, 0.0.0.0:8000->8000/tcp, :::8000->8000/tcp fastapi-application
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
After the application starts, navigate to `http://localhost:8000` in your web browser and you should see the following json response:
|
|
|
|
|
```
|
|
|
|
|
{
|
|
|
|
|
"message": "OK"
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Stop and remove the containers
|
|
|
|
|
```
|
2022-05-10 09:59:25 +00:00
|
|
|
|
$ docker compose down
|
2021-10-10 21:38:34 +00:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|