I’m currently trying to port my webapp from heroku to App Platform, and I’m struggling to use env variable set in the App Platform UI in my docker build phase. Any idea? Thanks

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

You can pass the values of environment variables from the host to your containers without much effort. Simply don’t specify a value in the command line, and make sure that the environment variable is named the same as the variable the containerized app expects:

$ docker run -e varname (…)
In the above snippet, the value of a var
name variable in the current environment is used to set the value of var_name in the container environment upon startup.

  • It seems that for docker run, App Platform passes the env variables, but not for docker build, where I need to specify them using --build-arg.

    [EDIT] But I do not have the option to specify a build script in App Platform, maybe because it has detected the Dockerfile. Still investigating.

    [EDIT] In the end, it seems that DO actually send env variables to the docker build phase, but I needed to “declare” it as expected in my Dockerfile using ARG NODE_ENV

    Thanks !

Submit an Answer