Question

DO App Plaform - Docker and Env variables

Posted April 30, 2021 347 views
DockerDeploymentDigitalOcean App Platform

I built a docker container with a NextJS app, using nginx as reverse proxy as we need it for advanced setups like proxy pass, etc.

It gets data from a headless CMS. It works fine locally.

However, when building it on DO App Platform, it’s fails cause it doesn’t detect the Environment Variables, even though I’ve set it up in the application container settings.

Is there a specific way I need to deploy it to take the Env Vars into account?

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.

×
Submit an Answer
1 answer

Hello, we may need more details to be able to help… But one thing to note is that environment variables are only available as build-args for Dockerfile builds in App Platform. So you should declare them in the Dockerfile as an ARG and then set the ENV variable in the Dockerfile from the build-arg.

If for example you set MY_ENV_VAR env var in application spec file or via App Platform UI, then something like this may work to actually pass that value into the container:

ARG MY_ENV_VAR
ENV MY_ENV_VAR=${MY_ENV_VAR}

Hope this helps.