Environment variables can be passed with the -e option when running docker run. Used to pass configuration information.
$ docker run --help | grep -e "-e"
-e, --env list Set environment variables
Verification
$ docker run -it --rm -e HOGE=FUGA -e AAA=BBB centos:centos8 /bin/bash
[root@45aa4a408e51 /]# echo $HOGE
FUGA
[root@45aa4a408e51 /]# echo $AAA
BBB
[root@45aa4a408e51 /]#
You can also pass environment variables from a file in which environment variables are written by using --env-file.
.env_test
HOGE=FUGA
A=B
TEST=TESTdesu
$ docker run --env-file ./.env_test --rm -it centos:centos8 /bin/bash
[root@d9801c8c2542 /]# echo $HOGE
FUGA
[root@d9801c8c2542 /]# echo $A
B
[root@d9801c8c2542 /]# echo $TEST
TESTdesu
Recommended Posts