How can I pass Jenkins environment variables to docker container?
Solution 1
you can set all your variables in .env
file and give it to when docker going to run your container:
TBS_END_POINT=http://192.168.82.2:2020/QWEr
MONGO_HOST=172.17.0.3
MONGO_PORT=27017
REPLICA_SET=replicaset
API_PORT=3001
REDIS_PORT=4432
NODE_ENV=development
then when you want to run you container say:
docker run --env-file .env MyImage
Solution 2
Did you try
docker run -e
https://docs.docker.com/engine/reference/run/#env-environment-variables
$ export today=Wednesday
$ docker run -e "deep=purple" -e today --rm alpine env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=d2219b854598
deep=purple
today=Wednesday
HOME=/root
or
$ docker run -d --name tst -e TESTME=YES busybox tail -f /dev/null
55a3fe206588a8030365df30a670ca89a50c54816d044184d5870a4a76ce8199
$ docker exec -it tst sh
/ # echo $TESTME
YES
/ #
wagng
Provide the best service with detail-oriented professional with a vast knowledge of software, framework and strong leadership skills seeking to well-versed in structuring, developing and implementing interactive mobile app development in Java, Swift, Objective-C, Ionic and React Native, backend development in Node.js, assisting clients in all troubleshooting endeavors.
Updated on June 13, 2022Comments
-
wagng almost 2 years
I am using Jenkins pipeline to build and deploy a docker container.
What I want to do is to pass Jenkins environment variables to docker container.
See the screenshot.
I defined the environment variables on Jenkins.
I check the docker container environment variables using the following commands
- docker exec -it docker_id bash (get into the docker) - printenv (print environment variables)
I want to see the Jenkins environment variables in docker container.
Is this possible? If so, please let me know the way to do it.
Thanks in advance!