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

Issue

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

Resolution

When deploying a container app on Heroku, we require that Dockerfiles be 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:

PORT=8080
EXPOSE $PORT
CMD gunicorn --bind 0.0.0.0:$PORT wsgi

We ask that you do something like this:

CMD gunicorn --bind 0.0.0.0:$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
Terms of Service Privacy Cookies © 2020 Salesforce.com