3 months ago
I wanted to deploy my backend API with Docker, and I have this issue. I tried almost every possible option, including solutions from similar problems that Railway support helped other developers with, but the issue remains the same:
Error: '$PORT' is not a valid port number.
Pinned Solution
3 months ago
You're overriding your working entrypoint.sh with Railway's start command field, which doesn't expand $PORT.
remove the entrypoint.sh from railways settings and dockerfile will handle it. Because in the dockerfile you already have here:
# Make entrypoint executable RUN chmod +x ./entrypoint.sh
10 Replies
3 months ago
Can you share your docker file?
3 months ago
you are passing the PORT as a string which probably won't work. There are some solution, and I don't know what have you tried so far, maybe like this:
CMD ["node", "server.js", "--port", "$PORT"]
but try this, which will expand the variable from shell:
CMD node server.js --port $PORT
Or put it in the env variables and read it:
const port = process.env.PORT || 3000;
then you can try only:
CMD ["node", "server.js"]
3 months ago
Thanks for trying to help me.
dardameiz
you are passing the PORT as a string which probably won't work. There are some solution, and I don't know what have you tried so far, maybe like this:CMD ["node", "server.js", "--port", "$PORT"]but try this, which will expand the variable from shell:CMD node server.js --port $PORTOr put it in the env variables and read it:const port = process.env.PORT || 3000;then you can try only:CMD ["node", "server.js"]
3 months ago
I uploaded the Dockerfile and screenshot of the entrypoint.sh file.
Attachments
dardameiz
you are passing the PORT as a string which probably won't work. There are some solution, and I don't know what have you tried so far, maybe like this:CMD ["node", "server.js", "--port", "$PORT"]but try this, which will expand the variable from shell:CMD node server.js --port $PORTOr put it in the env variables and read it:const port = process.env.PORT || 3000;then you can try only:CMD ["node", "server.js"]
3 months ago
In railway start command, I have (gunicorn portify.wsgi:application --bind 0.0.0.0:$PORT)
dardameiz
you are passing the PORT as a string which probably won't work. There are some solution, and I don't know what have you tried so far, maybe like this:CMD ["node", "server.js", "--port", "$PORT"]but try this, which will expand the variable from shell:CMD node server.js --port $PORTOr put it in the env variables and read it:const port = process.env.PORT || 3000;then you can try only:CMD ["node", "server.js"]
3 months ago
The entrypoint.sh file
Attachments
3 months ago
You're overriding your working entrypoint.sh with Railway's start command field, which doesn't expand $PORT.
remove the entrypoint.sh from railways settings and dockerfile will handle it. Because in the dockerfile you already have here:
# Make entrypoint executable RUN chmod +x ./entrypoint.sh
3 months ago
it worked Dardameiz. Your support has meant everything to me. And it saved me alot of time. Is there a way I can pay you or donate you.
Status changed to Solved brody • 3 months ago


