R
Railway12mo ago
apsys

Node + fastapi

Hey guys, I really struggle with setting up back container (fastapi, uvicorn, dockerfile) on railway. Basically it only works when container is fully rebuilt and deployed again. Looks like there is no entry point/cmd detected on reload/push to component. Is there anything I am missing ? (Whole project work perfectly fine on my local machine) Also the deploy logs don’t appear at all. Build logs are always finished, without error (last message is pushed $commit_name) , but after like 10 min mark everything crashes. Dockerfile FROM python:3.9-bullseye WORKDIR /app RUN apt-get update && apt-get install -y libgl1-mesa-glx libglib2.0-0 libsm6 libxext6 libxrender-dev tesseract-ocr libtesseract-dev freeglut3-dev tesseract-ocr-all wget COPY requirements.txt requirements.txt RUN pip3 install -r requirements.txt COPY . . EXPOSE 80 ENTRYPOINT [ "/bin/bash", "-c","cd src; uvicorn main:app --host 0.0.0.0 --port 80"]
Solution:
You should not be binding to a port. The docket file gets a new layer added to it with all your service environment variables and a PORT environment variable. That what it should be listening on for uvicorn.
Jump to solution
24 Replies
Percy
Percy12mo ago
Project ID: N/A
apsys
apsys12mo ago
N/A
Brody
Brody12mo ago
FROM python:3.9-bullseye

RUN apt-get update && apt-get install -y --no-install-recommends \
libgl1-mesa-glx \
libglib2.0-0 \
libsm6 \
libxext6 \
libxrender-dev \
tesseract-ocr \
libtesseract-dev \
freeglut3-dev \
tesseract-ocr-all \
wget

WORKDIR /app

COPY requirements.txt ./

RUN pip install -r requirements.txt

COPY . ./

CMD uvicorn main:app --host 0.0.0.0 --port $PORT
FROM python:3.9-bullseye

RUN apt-get update && apt-get install -y --no-install-recommends \
libgl1-mesa-glx \
libglib2.0-0 \
libsm6 \
libxext6 \
libxrender-dev \
tesseract-ocr \
libtesseract-dev \
freeglut3-dev \
tesseract-ocr-all \
wget

WORKDIR /app

COPY requirements.txt ./

RUN pip install -r requirements.txt

COPY . ./

CMD uvicorn main:app --host 0.0.0.0 --port $PORT
try that
apsys
apsys12mo ago
Thanks will be back in a min Also wanted to mention that experience with node (nextjs) was exceptional, launched via nixpacks in a literal minute. Its that complex fastapi apps which are very hard to get right on unknown hardware without terminal access
Brody
Brody12mo ago
you can run docker locally
apsys
apsys12mo ago
yeah i was thinking about it for this whole day, i was hoping that my small adjustments would make it work but i dont think so now
Brody
Brody12mo ago
well whats the verdict with the new dockefile
apsys
apsys12mo ago
pushing rn
Brody
Brody12mo ago
why tf is it 5gb???
apsys
apsys12mo ago
idk it shouldnt be but my guess is torch + tesseract + detectron models i will actually try to shrink down container locally
apsys
apsys12mo ago
btw
Brody
Brody12mo ago
full logs please
apsys
apsys12mo ago
Container failed to start =========================  /router.Router/StartDeployment UNKNOWN: Error response from daemon: No such container: cca0ba7790eb46eada48a65a7bbd884ffe666b3366c513fe4837b525f9e7ee78 thats the actual error, eberything before was alr i swear i guess it just didnt provision cause of size of it
Brody
Brody12mo ago
yeah you need to work on cutting the size down significantly
apsys
apsys12mo ago
thank you i will be back when (if) i manage to do so probably tomorrow since its already a night for me
Brody
Brody12mo ago
sounds good good luck!
apsys
apsys12mo ago
Thanks ! Hi again, so I validated that my container is working as expected on local, it’s size is 2.5gb, but on railway it builds it into 3.7 for whatever reason. Same problem as before I guess it just don’t publish it
apsys
apsys12mo ago
last logs before it gets "active" and crashes after a while
apsys
apsys12mo ago
Yo just changed torch version and it became 1 gig
apsys
apsys12mo ago
@Brody i think i got the container to work. Now its a networking issue. I added my port to variables (80), exposed it in dockerfile and so on, its just that that my api is still inaccessible (from private or public). I tried http and https(to be sure) but it only gives application failed to respond page. My api should work via http://myurl{railway stuff}:80/api/decks but there is nothing there on any type of method request. (I have cors on my fastapi with any origin allowed)
Solution
MantisInABox
MantisInABox12mo ago
You should not be binding to a port. The docket file gets a new layer added to it with all your service environment variables and a PORT environment variable. That what it should be listening on for uvicorn.
MantisInABox
MantisInABox12mo ago
Also, refrain from tagging conductors/team members directly #🛂|readme #5
apsys
apsys12mo ago
Oh ok thanks Anyway I think I will just rewrite everything in js It’s so much simpler
MantisInABox
MantisInABox12mo ago
If you are using fastapi, you can also check out the template that is working on railway https://railway.app/template/-NvLj4 This will also copy the repo to your GitHub account so you can modify and redeploy as necessary Or you can just check out how to get things configured