The objective of having the PORT environment variable in your node application is that you can specify a dynamic port to run your app and that is the best way to make sure that your container and your app are using the same port to communicate with each other. We usually run the docker application through a docker-compose.yaml file, or maybe your application can be managed by an orchestrator which will for sure require a dynamic environment variable to define the ports.
In conclusion, basically having a port defined via an environment variable provides a unified way to declare which port your app should be running.
what if i wanted to run all 3 containers on the same app?
in my local development mode, all 3 containers run on their own port 3000.
i tied my host port 3000 to the reverse proxy container's port 3000
so now from my host, only reverse proxy is accessible, and i only needed one port to run 3 containers.
but in heroku, if i tie one container to the $PORT, what about the other 2 containers?
so i didnt want to run all the containers on the $PORT provided by heroku.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
The objective of having the
PORT
environment variable in your node application is that you can specify a dynamic port to run your app and that is the best way to make sure that your container and your app are using the same port to communicate with each other. We usually run the docker application through adocker-compose.yaml
file, or maybe your application can be managed by an orchestrator which will for sure require a dynamic environment variable to define the ports.In conclusion, basically having a port defined via an environment variable provides a unified way to declare which port your app should be running.
to make sure that your container and your app are using the same port to communicate with each other.
actually, i wanted to run 3 containers on the same app -
i ultimately went on to make 3 separate heroku apps, one for each container, which works absolutely fine.
what if i wanted to run all 3 containers on the same app?
but in heroku, if i tie one container to the $PORT, what about the other 2 containers?
so i didnt want to run all the containers on the $PORT provided by heroku.