How do I use the $PORT environment variable in container based apps?


I am unsure where to use the $PORT environment variable in my Dockerfile for a container app


When deploying a container app on Heroku, we require that Dockerfiles are configured to intake the randomly assigned port on a dyno - exposed as the $PORT environmental variable.

Even though Docker allows for the usage of EXPOSE to specify which port for an image to use, Heroku ignores those commands and goes by the port assigned to a dyno.

For example, instead of this:

CMD gunicorn --bind$PORT wsgi

We ask that you do something like this:

CMD gunicorn --bind$PORT wsgi

Ask on Stack Overflow

Engage with a community of passionate experts to get the answers you need

Ask on Stack Overflow

Heroku Support

Create a support ticket and our support experts will get back to you

Contact Heroku Support