-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
How to start the backend server without using docker? #1111
-
How can I start the backend server without using docker?
Beta Was this translation helpful? Give feedback.
All reactions
It's described here in docs: https://github.com/fastapi/full-stack-fastapi-template/blob/master/development.md#local-development
In docs it's assumed you have already activated venv and installed dependencies
So, basically:
- activated venv and installed dependencies (do it once you created project)
# assuming you are in the root directory of the project
cd backend
uv sync
source .venv/bin/activate
cd ..
- Run backend containers, stop container with fastapi app, run fastapi app locally (on host machine)
# assuming you are in the root directory of the project
docker compose watch
docker compose stop backend
cd backend
fastapi dev app/main.py
Replies: 6 comments 6 replies
-
I have the same question.
Beta Was this translation helpful? Give feedback.
All reactions
-
Everything works for me with Docker. Without Docker, I tryed with virtualenv but it didn't find the solution for the moment...
Beta Was this translation helpful? Give feedback.
All reactions
-
Beta Was this translation helpful? Give feedback.
All reactions
-
in which directory we should run this command ?
Beta Was this translation helpful? Give feedback.
All reactions
-
cd backend the backend folder root, where the fastapi backend lives
Beta Was this translation helpful? Give feedback.
All reactions
-
I'm struggling to understand which command is intitializing the backend in production? because the Dockerfile doesn't have this uvicorn main:app --reload
Beta Was this translation helpful? Give feedback.
All reactions
-
The docker-compose.override runs command: /start-reload.sh, it most be already on the image from where the backend is build tiangolo/uvicorn-gunicorn-fastapi:python3.10
Beta Was this translation helpful? Give feedback.
All reactions
-
the Dockerfile runs uvicorn main:app --reload when importing the Dockerfile from FROM tiangolo/uvicorn-gunicorn-fastapi:python3.10
with command CMD ["/start.sh"] is there!
however `COPY ./app /app/app takes place till the end here .
How is unicorn being executed without the app? does this mean CMD at the end of tiangolo/uvicorn-gunicorn-fastapi:python3.10 is somehow delayed?
I see that docker-compose.override.yml has
command: /start-reload.sh
which executes uvicorn
however I can't understand how does docker-compose.yml work in production
Beta Was this translation helpful? Give feedback.
All reactions
-
The Dockerfile just have instructions tu build an image, copy the files, install necessary packages on the image...doesn't run or execute the container. To run a single container from an image you would use the command docker run [image]... but docker compose let you build multiple images from different Dockerfiles and then run the containers for each image.
If you run "docker compose up -d" and then "docker compose exec backend batch" you can cd and explore the files inside the container and your will find start-reload.sh which executes uvicorn once the backend container is running.
Beta Was this translation helpful? Give feedback.
All reactions
-
I have made a similar setup for backend without using docker. async sqlalchemy + pydantic schemas (without sqlmodels) are used there though.
Take a look: Async FastAPI SQLAlchemy Template.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 2
-
Thank you @gospodima !
Beta Was this translation helpful? Give feedback.
All reactions
-
It's described here in docs: https://github.com/fastapi/full-stack-fastapi-template/blob/master/development.md#local-development
In docs it's assumed you have already activated venv and installed dependencies
So, basically:
- activated venv and installed dependencies (do it once you created project)
# assuming you are in the root directory of the project
cd backend
uv sync
source .venv/bin/activate
cd ..
- Run backend containers, stop container with fastapi app, run fastapi app locally (on host machine)
# assuming you are in the root directory of the project
docker compose watch
docker compose stop backend
cd backend
fastapi dev app/main.py
Beta Was this translation helpful? Give feedback.