By jitheshkt
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?
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!
I figured it out.
We should define our env variable as ARG at the beginning of the Dockerfile like this:
ARG ENVIRONMENT
Then we can access it later with ${ENVIRONMENT}
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.