Question

How to use App Platform's bindable environment variables in Dockerfile

I was following the tutorial on How to Use Environment Variables in App Platform, and I am unable to figure out how to use these convenience variables in my Dockerfile.

I am specifically trying to print the COMMIT_HASH to a file in the container of my web component.

ARG web.COMMIT_HASH=unspecified
RUN echo ${web.COMMIT_HASH} > /www/commithash.txt

I’ve also tried pulling it in using ENV but that fails during build.

ENV GITHASH=${web\.COMMIT_HASH:-unspecified}
RUN echo ${GITHASH} > /www/githash.txt

It errors out at the . dot.

So is there a way to get these convenience environment variables into my Dockerfile?

Any help is greatly appreciated.


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.

Jon Friesen
DigitalOcean Employee
DigitalOcean Employee badge
November 4, 2020
Accepted Answer

👋 @echoTHIS

Great question, bindable variables are a template system for environment variables, not environment variables themselves.

You could create a environment variable called GITHASH with a value of ${web.COMMIT_HASH} in the DO App Platform UI. When we build or deploy your app we will inject an environment variable of $GITHASH with your commit hash.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

card icon
Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Sign up
card icon
Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We’d like to help.

Learn more
card icon
Become a contributor

You get paid; we donate to tech nonprofits.

Learn more
Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow – whether you’re running one virtual machine or ten thousand.

Learn more ->
DigitalOcean Cloud Control Panel