Accessing environment variable inside Dockerfile - App Platform


I am running a website on DigitalOcean App Platform. I have couple of environment variables already configured and working fine. But What I am now trying to do is, I want to access a environment variable inside Dockerfile during build time. My use case is like below:


CP ./config/staging/conf.d /etc/nginx/conf.d

As you can see, I am trying to make the staging string into an environment variable so that I can use it on both my staging & production branches.

I tried something like this:

CP ./config/${ENVIRONMENT}/conf.d /etc/nginx/conf.d

But it didn’t work. Can someone help me?

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

I figured it out.

We should define our env variable as ARG at the beginning of the Dockerfile like this:


Then we can access it later with ${ENVIRONMENT}