awesome-compose/fastapi
2023-02-02 16:58:51 +00:00
..
.docker fastapi: add dev envs support 2022-07-05 11:59:35 -04:00
app Add fastapi to the list of compose projects 2021-10-10 23:38:34 +02:00
compose.yaml Update 'fastapi/compose.yaml' 2023-02-02 16:58:51 +00:00
Dockerfile fastapi: add dev envs support 2022-07-05 11:59:35 -04:00
README.md Add "Open in Docker Dev Environments" links (#280) 2022-09-01 11:39:33 -05:00
requirements.txt Add fastapi to the list of compose projects 2021-10-10 23:38:34 +02:00

Compose sample application

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 Open in Docker Dev Environments

Python/FastAPI application

Project structure:

├── compose.yaml
├── Dockerfile
├── requirements.txt
├── app
    ├── main.py
    ├── __init__.py

compose.yaml

services:
  api:
    build: .
    container_name: fastapi-application
    environment:
      PORT: 8000
    ports:
      - '8000:8000'
    restart: "no"

Deploy with docker compose

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