How to npm run start with SPECIFIC PORT? (for each docker service)
Unanswered
Little Shearwater posted this in #help-forum
Little ShearwaterOP
I guess I gotta create the entire forum just for a single question since I cannot chat on #discussions 

23 Replies
Little ShearwaterOP
Next run -p ____
would cause MODULE NOT FOUND
issue, I am not sure whyUsually that's dependencies issue but I cannot confirm it.
Though my docker image already installs all required dependacies.
IF any of you cannot resolve this issue, you can just answer my original question (or give any workaround)
IF any of you cannot resolve this issue, you can just answer my original question (or give any workaround)
@Little Shearwater I guess I gotta create the entire forum just for a single question since I cannot chat on <#752647196419031042> <:shrug:1158792691052716082>
you can do it with the
PORT
environment variablePORT=4000 npm start
@joulev you can do it with the `PORT` environment variable
PORT=4000 npm start
Little ShearwaterOP
Depending on the enviroment (windows and linux)
1. PORT not found on window terminal
2. The command executed but it seems that NextJS ignored the port (and went with default 3000) on Ubuntu terminal
1. PORT not found on window terminal
2. The command executed but it seems that NextJS ignored the port (and went with default 3000) on Ubuntu terminal
i don't know about windows, but linux should be fine. your docker image should be a linux distro
@joulev really? cuz i used it just now and it works just fine
Dutch Smoushond
yeah this works for me too, (i'm on linux tho)
you can also define the port in the package.json with the
--port
flagLittle ShearwaterOP
Interesting, I added some enviroment variables in
enviroment
in a docker compose file which resolves the issue (since it handles multiple containers and it allow me to define an unique port for each one)@Dutch Smoushond you can also define the port in the package.json with the `--port` flag
Little ShearwaterOP
This wouldn't work if I wanted to have more than one docker container running (they cannot share same port)
@joulev really? cuz i used it just now and it works just fine
Little ShearwaterOP
Could it have been another package manager (pnpm)?
Oh and if I were to run a command inside docker container, it would cause
/app/PORT=4000 NOT FOUND
(which doesn't make sense)I wonder if there are other solutions than my current solution?
maybe better?
It looks like this is the best solution I got right now that supports multiple-containers.
@Little Shearwater Could it have been another package manager (pnpm)?
No. Using
--port
or the PORT env var both work to configure the port that the nextjs server listens on. If it doesn’t work for you, it’s because your docker configuration is buggy.@joulev No. Using `--port` or the PORT env var both work to configure the port that the nextjs server listens on. If it doesn’t work for you, it’s because your docker configuration is buggy.
Little ShearwaterOP
Really? Honestly I've never seen it before.
Really?Yes.
Trigg Hound
if I remember correctly, I don't think you can't inject environment variables in windows using the
PORT=<number> pnpm start
syntax unless you are using the cross-env package, but I could be wrong.Yeah on windows env vars work differently
can't you just change the bind port on docker?