source: https://github.com/tiangolo/uvicorn-gunicorn-fastapi-docker#quick-start source: https://codeburst.io/implement-a-production-ready-rest-service-using-fastapi-13f284562c75
Change main.py
From same folder run: uvicorn main:app --reload
This will provide hot reload of webserver when changes are made to main.py
docker-compose up --build
will start a webserver on localhost:8001
and documentation on localhost:8001/docs
Extension to install: Remote-Containers Then in bottom left corner press green icon. (ctrl+shift+p -> Remote-Containers: attach to running container) choose "fast_api_server" from the list of running containers
open a terminal in vs code (it will open as root in the container). enter: uvicorn main:app --reload
-> ctrl+click on the server link. A browser will open to show the api server
Make changes to main.py and see how the server is reloaded and changes takes effect in browser.
- Inside the devcontainer.json file add:
"remoteUser key": "vscode",
in order to be logged in as vscode instead of root in the terminal (This means that ownership of new files will not be root and thereby locked for other users.). This was NOT WORKING since creating the user in the Dockerfile meant that existing files could not be editted by that user (Could not give it sudo privileges). LOOK more in to this