Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we use local env variable in Docker file COPY command?

Tags:

docker

Can I use host env variable in source part of COPY command in Dockerfile.
Eg: I have env varianle MY_HOME = /abc/def

Can I use following in Dockerfile?

COPY ${MY_HOME}/xyz.conf /ams/config/xyz.conf
like image 237
Chandu Avatar asked Jan 31 '26 07:01

Chandu


1 Answers

You can use environment variables like RUN echo $HOME > /home.txt. But be aware of the fact, that in COPY commands you can only use files that are in the build context.

The docker build command builds Docker images from a Dockerfile and a “context”. A build’s context is the set of files located in the specified PATH or URL. The build process can refer to any of the files in the context. For example, your build can use a COPY instruction to reference a file in the context.

like image 67
codinghaus Avatar answered Feb 01 '26 19:02

codinghaus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!