#How to get the default PORT in Nixpacks?
42 messages · Page 1 of 1 (latest)
Project ID: N/A
N/A
generating the PORT variable is not done by the nixpacks builder, railway generates the PORT before it runs the docker image
You should just be able to retrieve the PORT env variable. No need to put it in the dockerfile
Thank you for the response!
Can you suggest a method that I should use to auto generate the PORT?
Thank you for the response!
I am doing the same but wanted to auto generate the PORT with respect to provider. Is there any way I can handle the PORT auto generation?
its just a random number generator between 5000 to 8000 or something like that
Sorry, for the noob question, is port number between 5000 to 8000 will work for any language or framework?
Ex.: I tried running Astro on Port 80 but it didn't worked, so I thought we might need to generate default port with respect to framework or languages. In case they've not defined something custom in their project.
let's back up, first how are you even running astro?
I've generated the dockerfile from Nixpacks and then build image using that dockerfile and Kaniko and then deployed to K8s Pod to run on port 80 but it didn't worked.
I didn't gave any start command thinking Nixpacks generated dockerfile handles these
here is an astro template that will work on railway
https://github.com/brody192/astro-basic-template
you will need to use the node adapter like that template uses, read more about it here
https://docs.astro.build/en/guides/integrations-guide/node/
I understand now, so it's not the PORT issue but rather node adapter issue.
Is there any guide available for other framework? Also, this issue is just with Node related framework not with other languages/frameworks.
guides for what exactly
I mean Nixpacks template for all the supported languages and frameworks.
there this
https://railway.app/templates
but that doesnt cover every framework that could run on railway/nixpacks, it would be impossible
but thats why we have the #help channel
I tried running on the random port 5000 but it is giving me 502 Bad Gateway the reason the server is listening to 3000
> @example/[email protected] start
> node dist/server/entry.mjs
Server listening on http://0.0.0.0:3000
it will listen on 3000 if you don't specify a port with a PORT environment variable
3000 is the default value
I have specified 5000
you have not, otherwise it would say 5000
Ok, so we have to add the PORT with ENV during building the image itself then it will listen to the defined port?
I have not actually used nixpacks to build docker images locally, so I can't comment on how you would do it, all I know is that if there is a PORT environment variable defined, my template will listen on it
I have another query, defining port in env will work in a framework like Astro but
What if the project doesn't defines the port in env and rather it defines in file like this example https://expressjs.com/en/starter/hello-world.html then will it listen to defined port from env?
then you would need to access the app via the port it has hardcoded
So, we've to manually add it, I mean there is no way random port will work, right?
if you generate a random number (5000-8000) and then pass that random number in as a PORT environment variable, my template will listen on that random number
I am editing the Nixpacks config with CLI reference to test this. I'll update you here.
I followed the CLI ref. to add port in env during the build and it worked. Thanks a lot for your help!
Do I have to do anything to mark this post as resolved?