2 years ago
I am trying to deploy a FastAPI app without success getting a socket.gaierror. I guess this is due to empty $PORT with dockerfile giving no exposed port.
I also tried to set the PORT value to 8000 without success.
I looked at the document without success.
It's my first time deploying from dockerfile. Any help is apreciated !
The build is done within dockerfile:
'''
…
WORKDIR /opt/
COPY . .
RUN echo "PORT: ${PORT}"
EXPOSE $PORT
''''
Build logs printing empty PORT value
'''
14 [10/10] RUN echo "PORT: ${PORT}"
14 0.325 PORT:
'''
Startcommand from railway.json:
'''
"startCommand": "hypercorn app:app --bind \"[::]:$PORT\"",
''''
Deployment logs error:
'''
insecuresockets = self.create_sockets(self.bind)
File "/usr/local/lib/python3.10/site-packages/hypercorn/config.py", line 266, in _create_sockets
sock.bind(binding)
socket.gaierror: [Errno -2] Name or service not known
'''
ⓘ Deployment information is only viewable by project members and Railway employees.
4 Replies
2 years ago
It seems the code formating is not good. Here is the logs with ` formating:
The build is done within dockerfile:
WORKDIR /opt/
COPY . .
RUN echo "PORT: ${PORT}"
EXPOSE $PORTBuild logs printing empty PORT value
#14 [10/10] RUN echo "PORT: ${PORT}"
#14 0.325 PORT:Startcommand from railway.json: "startCommand": "hypercorn app:app --bind \"[::]:$PORT\"",
Deployment logs error:
Traceback (most recent call last):
File "/usr/local/bin/hypercorn", line 8, in
sys.exit(main())
File "/usr/local/lib/python3.10/site-packages/hypercorn/__main__.py", line 287, in main
run(config)
File "/usr/local/lib/python3.10/site-packages/hypercorn/run.py", line 38, in run
sockets = config.create_sockets()
File "/usr/local/lib/python3.10/site-packages/hypercorn/config.py", line 203, in create_sockets
insecure_sockets = self._create_sockets(self.bind)
File "/usr/local/lib/python3.10/site-packages/hypercorn/config.py", line 266, in _create_sockets
sock.bind(binding)
socket.gaierror: [Errno -2] Name or service not known2 years ago
Because I couldn't get the value of $PORT variable, even in the input start command filed from railway settings, I decided to hardcoded the port and it works fine.
2 years ago
The PORT variable is not available at build time, you should not use it anywhere in your Dockerfile besides in CMD (the command ran at runtime)
I would recommend omitting the startCommand in the railway.json and instead set CMD line to CMD hypercorn app:app --bind "[::]:$PORT"
Status changed to Solved Railway • almost 2 years ago
2 years ago
Thank you for the anwser @brody.