Unable to deploy Fastapi backend container
jamesheavey
PROOP

10 months ago

I am trying to build and deploy the FastAPI backend of a monorepo I have.

The nextjs frontend built and deployed successfully, however the backend builds and then hangs in the deploy stage. The only message in the Deploy Logs is "Starting Container".

I dont know why this isnt working or how I can go about debugging.

The dockerfile I am using builds and runs locally.

Solved

7 Replies

10 months ago

Hello,

Your start command is likely incorrect - python main.py

Typically, FastAPI apps are started via uvicorn.

Best,
Brody


Status changed to Awaiting User Response Railway 10 months ago


brody

Hello,Your start command is likely incorrect - python main.pyTypically, FastAPI apps are started via uvicorn.Best,Brody

jamesheavey
PROOP

10 months ago

Ah that sounds about right, I am defining the start commands in the Dockerfile, is that not a valid way to do it?


Status changed to Awaiting Railway Response Railway 10 months ago


10 months ago

It is a valid way to do it, it's just that you aren't using uvicorn.


Status changed to Awaiting User Response Railway 10 months ago


brody

It is a valid way to do it, it's just that you aren't using uvicorn.

jamesheavey
PROOP

10 months ago

I have specified the start command to be uvicorn in the dockerfile

FROM python:3.12

WORKDIR /app

COPY ./requirements.txt .

RUN pip install --no-cache-dir --upgrade -r requirements.txt

COPY . .

EXPOSE 8000

CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]

Status changed to Awaiting Railway Response Railway 10 months ago


jamesheavey

I have specified the start command to be uvicorn in the dockerfileFROM python:3.12 WORKDIR /app COPY ./requirements.txt . RUN pip install --no-cache-dir --upgrade -r requirements.txt COPY . . EXPOSE 8000 CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]

jamesheavey
PROOP

10 months ago

I just tried to manually override the start command and that didnt work. Also I noticed in the build logs, it appears that it ran and started the server there?

```
[stage-0 6/10] RUN --mount=type=cache,id=s/8dc4cd99-04b5-4fa0-824e-14c44f74249c-/root/cache/pip,target=/root/.cache/pip python -m venv --copies /opt/venv && . /opt/venv/bin/activate && pip install -r requirements.txt heavy_check_mark emoji 2m 55s

May 07 20:57:39

[stage-0 7/10] COPY . /app/.

May 07 20:57:40

[stage-0 7/10] COPY . /app/. heavy_check_mark emoji 679ms

May 07 20:57:40

[stage-0 8/10] RUN uvicorn main:app --host 0.0.0.0 --port 8000

May 07 20:57:48

INFO: Started server process [1] INFO: Waiting for application startup.

May 07 20:58:12

Error rendering graph: [Errno 2] No such file or directory: '../assets/ingester.png'

May 07 20:58:13

Error rendering graph: [Errno 2] No such file or directory: '../assets/query_agent.png'

May 07 20:58:13

Error rendering graph: [Errno 2] No such file or directory: '../assets/visualise_agent.png'

May 07 20:58:13

Error rendering graph: [Errno 2] No such file or directory: '../assets/supervisor.png'

May 07 20:58:13

INFO: Application startup complete.

May 07 20:58:13

INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
```


10 months ago

Remove your CMD directive, and set it on Railway instead.

https://docs.railway.com/reference/build-and-start-commands


Status changed to Awaiting User Response Railway 10 months ago


ray-chen

Remove your CMD directive, and set it on Railway instead.https://docs.railway.com/reference/build-and-start-commands

jamesheavey
PROOP

10 months ago

Thanks guys, I managed to get it working by ditching dockerfiles altogether and manually setting the start command as you suggested


Status changed to Awaiting Railway Response Railway 10 months ago


Status changed to Solved jamesheavey 10 months ago


Loading...