DEV Community

Discussion on: How to Dockerize a Node app and deploy to Heroku

Collapse
 
pacheco profile image
Thiago Pacheco

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.

Collapse
 
shameekagarwal profile image
shameekagarwal • Edited

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 -

  1. for backend
  2. for frontend
  3. for 'reverse proxy'

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?

  1. in my local development mode, all 3 containers run on their own port 3000.
  2. i tied my host port 3000 to the reverse proxy container's port 3000
  3. 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.