[英]docker-compose: .env file is not loaded
My docker-compose.yml
我的docker-compose.yml
version: '3'
services:
test:
build: .
My Dockerfile
我的Dockerfile
FROM alpine:latest
ENTRYPOINT echo $ARG1 $ARG2
My .env
file我的.env
文件
ARG1=argument100
ARG2=argument200
If I run docker-compose run test
the empty line got printed.如果我运行docker-compose run test
,则会打印空行。 However, it I add env_file
section to my docker-compose.yml
I am getting the expected output.但是,我将env_file
部分添加到我的docker-compose.yml
中,我得到了预期的 output。
New docker-compose.yml
全新docker-compose.yml
version: '3'
services:
test:
build: .
env_file:
- .env
Running docker-compose
again再次运行docker-compose
$ docker-compose run test
argument100 argument200
Am I using an illegal way to pass arguments to the ENTRYPOINT
command inside the Docker
?我是否使用非法方式将 arguments 传递给 Docker 内的ENTRYPOINT
Docker
? Why is .env
not loaded automatically upon docker-compose run
?为什么在docker-compose run
时.env
没有自动加载?
The .env
file is used to set variables in the docker-compose command itself that can be used to expand variables in the docker-compose.yml file itself. .env
文件用于设置 docker-compose 命令本身中的变量,这些变量可用于扩展 docker-compose.yml 文件本身中的变量。 The env_file
specification will define variables inside the containers. env_file
规范将定义容器内的变量。 They operate at two different levels.他们在两个不同的层面上运作。
There's also a third type of variable, build args, that can be injected into the building of an image.还有第三种类型的变量,build args,可以注入到图像的构建中。
Each of these has a distinct purpose, and are not multiple ways to do the same thing.它们中的每一个都有不同的目的,并且不是做同一件事的多种方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.