Hot Reload Fast API within docker dev container

Viewed 563

I am trying to configure hot-reloading of a FastAPI running in a docker-compose dev container via VS Code. The service detects a reload, shuts down then does not restart. I get the error:

Finished server process [24]

Has anyone got a working example of this, with debugging support? Note: this only happens after you have invoked the service. Hot reloading works fine with multiple changes provided you dont invoke the service.

Docker compose file:

version: '3.7'

services:
  test-service:
    image: test-service
    container_name: test-service
    build: 
      context: ../..
      dockerfile: Dockerfile
      target: debug-tests
    ports:
      - 5000:5000
      - 5678:5678
    env_file:
      - local.env
    volumes:
      - ../src:/app
    entrypoint: [ "python3", "-m", "debugpy", "--listen", "0.0.0.0:5678", "-m", "uvicorn", "app:app", "--host", "0.0.0.0", "--port", "5000", "--reload", "--reload-dir", "/app"]

Cheers KH

0 Answers
Related