Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

How can I start the backend server without using docker?

You must be logged in to vote

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:

  1. 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 ..
  1. 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

Comment options

I have the same question.

You must be logged in to vote
0 replies
Comment options

Everything works for me with Docker. Without Docker, I tryed with virtualenv but it didn't find the solution for the moment...

You must be logged in to vote
0 replies
Comment options

you guys can run it using uvicorn main:app --reload @auh83 @achaosss @BladeSun

You must be logged in to vote
2 replies
@DanielGuarnizo
Comment options

in which directory we should run this command ?

@machov
Comment options

cd backend the backend folder root, where the fastapi backend lives

Comment options

I'm struggling to understand which command is intitializing the backend in production? because the Dockerfile doesn't have this uvicorn main:app --reload

You must be logged in to vote
3 replies
@carlos-dz
Comment options

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

@machov
Comment options

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

@carlos-dz
Comment options

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.

Comment options

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.

You must be logged in to vote
1 reply
@auh83
Comment options

Thank you @gospodima !

Comment options

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:

  1. 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 ..
  1. 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
You must be logged in to vote
0 replies
Answer selected by YuriiMotov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
8 participants
Converted from issue

This discussion was converted from issue #1101 on March 18, 2024 20:59.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.