awesome-compose/fastapi/README.md
Milas Bowman 035e3c5b43 fastapi: add dev envs support
Signed-off-by: Milas Bowman <milas.bowman@docker.com>
2022-07-05 11:59:35 -04:00

65 lines
1.5 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## Compose sample application
### Python/FastAPI application
Project structure:
```
├── compose.yaml
├── Dockerfile
├── requirements.txt
├── app
   ├── main.py
   ├── __init__.py
```
[_compose.yaml_](compose.yaml)
```
services:
api:
build: .
container_name: fastapi-application
environment:
PORT: 8000
ports:
- '8000:8000'
restart: "no"
```
## Deploy with docker compose
```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
```
$ docker compose down
```
## 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/fastapi
```