Hello,
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:
Dockerfile:
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?
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.
Click below to sign up and get $100 of credit to try our products over 60 days!
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}