[英]Docker-compose error with service env_file
I've been working on passing my sensitive data (credentials) to the docker container through a .env file. 我一直在通过.env文件将敏感数据(凭据)传递到Docker容器。 I'm using docker-compose and my docker-compose.yml file looks as follows:
我正在使用docker-compose,而我的docker-compose.yml文件如下所示:
services:
some-service:
env_file:
- .env
But when I try to do "docker-compose up", I get the below error: 但是,当我尝试执行“ docker-compose up”时,出现以下错误:
ERROR: In file './docker-compose.yml', service 'env_file' must be a mapping not an array.
My .env file has data like 我的.env文件中的数据如下
id = 1234567890 id = 1234567890
pwd = my_pwd pwd = my_pwd
Are there any indentation errors in my file? 我的文件中是否存在任何缩进错误? Any suggestions on how to fix this error?
关于如何解决此错误的任何建议?
Looks like this is a problem with your YAML structure. 看来这是您的YAML结构有问题。 It might be a missing space before your
- .env
or the missing service name. 您的
- .env
之前可能缺少空格,或者缺少服务名称。 Try this: 尝试这个:
services:
some-service:
env_file:
- .env
If you only use one environment file, you can also write: 如果仅使用一个环境文件,则还可以编写:
services:
some-service:
env_file: .env
See: https://docs.docker.com/compose/compose-file/#env_file 参见: https : //docs.docker.com/compose/compose-file/#env_file
ERROR: In file './docker-compose.yml', service 'env_file' must be a mapping not an array.
The error says that docker-compose believes env_file
is the name of your service rather than a setting on a service. 该错误表明
env_file
-compose认为env_file
是服务的名称,而不是服务上的设置。 This indicates you have not correctly indented the env_file
section to be within a service. 这表明您没有正确缩进
env_file
节在服务中。 YML syntax is white space sensitive, so double check the indentation on your lines. YML语法对空格敏感,因此请仔细检查行上的缩进。 If you can't find the error with your indentation, please include the full docker-compose.yml file in your question, indented exactly as it is in your file, for us to assist further.
如果您无法通过缩进找到错误,请在问题中包含完整的docker-compose.yml文件,该文件的缩进位置与文件中的内容完全相同,以便我们提供进一步的帮助。
The problem was not with the indentation. 问题不在于缩进。 Seems like it is working now.
好像现在正在工作。 I actually had to mention the version and build path(they were missing in my initial yml file).
我实际上不得不提到版本和构建路径(它们在我的初始yml文件中不存在)。 So the final docker-compose file would look like as follows:
因此,最终的docker-compose文件如下所示:
version: '3'
services:
some-service:
build: .
env_file:
- .env
or if you want you can associate it with a specific image name as: 或者,如果您愿意,可以将其与特定的图像名称相关联,例如:
version: '3'
services:
some-service:
build: .
image: image_name:image_version
env_file:
- .env
Hope this will help someone who run into the same issue 希望这对遇到同样问题的人有所帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.