Docker 中的环境变量
Environment variables in Docker
我想用一个.env-file
来描述我的变量:
URL: $HOST
PORT: $PORT
MAIL = “test@test.be”
PASS = “test123"
我想使用容器中的文件:
docker run --env-file myfile
但我想替换文件中的 $HOST 和 $PORT
我可以做这样的事情吗?
docker run --env-file myfile -e PORT="8080" -e "HOST=ec2-xxx"
这已经得到支持,唯一的问题是您需要确保您的 ENV 文件格式正确:
$ cat myfile
URL= $HOST
PORT= $PORT
MAIL= “test@test.be”
PASS= “test123
一旦您的 env 文件格式正确,您就可以使用 docker 运行 命令,如下所示:
$ docker run --env-file=myfile -e HOST=123.22 -e PORT=234 busybox env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=0d543af16a70
URL= $HOST
PORT=234
MAIL= “test@test.be”
PASS= “test123
HOST=123.22
HOME=/root
Please observe, in the above docker run command "busybox" is a
container and env
is the command that gets executed on running the
above command. In your case, you may change the container name, and be
assured that the env variables are properly sent.
我想用一个.env-file
来描述我的变量:
URL: $HOST
PORT: $PORT
MAIL = “test@test.be”
PASS = “test123"
我想使用容器中的文件:
docker run --env-file myfile
但我想替换文件中的 $HOST 和 $PORT 我可以做这样的事情吗?
docker run --env-file myfile -e PORT="8080" -e "HOST=ec2-xxx"
这已经得到支持,唯一的问题是您需要确保您的 ENV 文件格式正确:
$ cat myfile
URL= $HOST
PORT= $PORT
MAIL= “test@test.be”
PASS= “test123
一旦您的 env 文件格式正确,您就可以使用 docker 运行 命令,如下所示:
$ docker run --env-file=myfile -e HOST=123.22 -e PORT=234 busybox env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=0d543af16a70
URL= $HOST
PORT=234
MAIL= “test@test.be”
PASS= “test123
HOST=123.22
HOME=/root
Please observe, in the above docker run command "busybox" is a container and
env
is the command that gets executed on running the above command. In your case, you may change the container name, and be assured that the env variables are properly sent.