DEV Community


Discussion on: Deploying containerized NginX to Heroku - how hard can it be?

davisruk profile image

Thanks for this - I had the same problem and it put me on the right track.

One observation I have is that you don't really need to use ARG in your Dockerfile as it would only be available at image build time rather than container runtime. It's not actually doing anything in your file (the sed command gets run at container startup so the ARG is not actually available to it).

The reason that your solution is working is that Heroku creates a PORT environment variable when it instantiates the container (think -e when running docker containers locally) so you will always have access to this variable when the container is running on the Heroku platform.

However, if you run the container locally you have to provide the evironment variable yourself e.g. docker run -e PORT=4200 ...

If you don't want to do this then you can replace the ARG entry in your Dockerfile with an ENV statement and provide a default value eg. ENV PORT=4200. ENV values are available at container instantiation and can be overridden. Heroku will always override it and you can also run it locally without providing a command line environment variable.

Once again, thanks for the insight as it gave me what I needed to solve my issue.

annisalli profile image
Anniina Sallinen Author

Thank you, I'm happy that I could help! 🤩

And you're also right about the ARG, thank you for noticing it. I actually think I just forgot to remove it after I realised the PORT environment variable is defined in runtime and not in build time in Heroku 😄

Very nice explanation about how to define the environment variable when you run the container locally 😊 I don't have that information in my blog post, but that is definitely useful information!