Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to use environment variable in Dockerfile?

I am just experimenting with configuring Dockerfile-

FROM ubuntu:latest

RUN apt-get update

RUN echo VERSION_TAG="latest" >> /etc/environment

RUN cat /etc/environment

CMD echo $VERSION_TAG

I built the image using (I was in the req directory) –

docker build -t temp/testing:latest .

Ran it using-

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

docker run temp/testing:latest

Expected output-

latest

Actual Output-


While building the image, the output of cat /etc/environment

Step 4/5 : RUN cat /etc/environment
 ---> Running in 4grdc7b5165a
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"
VERSION_TAG=latest

It is present inside env variables, still, its value is not being printed, any help will be appreciated.

Note – I want to do it without using
https://docs.docker.com/engine/reference/builder/#env

>Solution :

I need to know the reason.

Docker just exec() the command ENTRYPOINT+CMD with nothing in between.

pam is not loaded, so pam_env.so is not loaded, so /etc/environment is not read.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading