Answer the question
In order to leave comments, you need to log in
How to pass an environment variable to a Docker container?
Hello,
for example, I have a Dockerfile
FROM ubuntu:14.04
ARG SOME_PASSWORD
RUN echo $SOME_PASSWORD >> file.password
ADD docker-entrypoint.sh /docker-entrypoint.sh
RUN chmod +x /docker-entrypoint.sh
ENTRYPOINT /docker-entrypoint.sh
docker build -t test_image .
docker run -e SOME_PASSWORD='password12345' --restart=always -it test_image
Answer the question
In order to leave comments, you need to log in
This variable will be set in your /docker-entrypoint.sh file. It remains only to put it in the desired file
cat > /password << EOL
password=$SOME_PASSWORD
EOL
So just read the variable from the file and pass it through the standard -e
We put the password in the file just by the value
echo "mysecretpassword" > file.password
...
MYVAR=$(cat file.password)
docker run -e SOME_PASSWORD="$MYVAR" --restart=always -it test_image
echo "MYVAR=mysecretpasswowrd">file.password
...
. file.password
docker run -e SOME_PASSWORD="$MYVAR" --restart=always -it test_image
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question