'Is there a possibility to remap Heroku PORT environment variable to another name?

I need to deploy an existing web application to Heroku using Docker and it expects the port to be passed as APPNAME_PORT and not PORT.

I know I can rebuild the Docker image to do the mapping internally, but it will be annoying to do as I'll need to have the altered Dockerfile I need to update the application. Is there a possibility to remap the environment variable to another name within Heroku?

Is there a way to do something like APPNAME_PORT=$PORT in Config Vars to store the PORT name into APPNAME_PORT environment variable?



Solution 1:[1]

Answer from Heroku support:

I'm afraid there's no native feature to alias config vars - you can do this for add-ons via the -as flag with the addons:attach command but that's only for add-ons which are irrelevant here. You would need to alias the port in your code.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dmitry Verhoturov