#How to get the default PORT in Nixpacks?

42 messages · Page 1 of 1 (latest)

crude socket
#

I am using Nixpacks in my local and I noticed the generated dockerfile doesn't provide PORT. How should we get the default PORT, so that we don't have to manually add for deployment.

distant pelicanBOT
#

Project ID: N/A

crude socket
#

N/A

open meteor
#

generating the PORT variable is not done by the nixpacks builder, railway generates the PORT before it runs the docker image

muted pollen
crude socket
crude socket
open meteor
#

its just a random number generator between 5000 to 8000 or something like that

crude socket
#

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.

open meteor
#

let's back up, first how are you even running astro?

crude socket
#

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.

open meteor
#

back up

#

how are you running astro

#

what's your start command

crude socket
#

I didn't gave any start command thinking Nixpacks generated dockerfile handles these

open meteor
#

in package.json

#

do you have a repo for the project you hope to build with nixpacks?

crude socket
open meteor
crude socket
#

I understand now, so it's not the PORT issue but rather node adapter issue.

open meteor
#

yes

#

kinda

crude socket
#

Is there any guide available for other framework? Also, this issue is just with Node related framework not with other languages/frameworks.

open meteor
#

guides for what exactly

crude socket
#

I mean Nixpacks template for all the supported languages and frameworks.

open meteor
#

but that doesnt cover every framework that could run on railway/nixpacks, it would be impossible

#

but thats why we have the #help channel

crude socket
#

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
open meteor
#

it will listen on 3000 if you don't specify a port with a PORT environment variable

#

3000 is the default value

crude socket
#

I have specified 5000

open meteor
#

you have not, otherwise it would say 5000

crude socket
#

Ok, so we have to add the PORT with ENV during building the image itself then it will listen to the defined port?

open meteor
#

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

crude socket
#

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?

open meteor
#

then you would need to access the app via the port it has hardcoded

crude socket
#

So, we've to manually add it, I mean there is no way random port will work, right?

open meteor
#

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

crude socket
crude socket
#

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?