【发布时间】:2018-10-10 13:08:32
【问题描述】:
我正在尝试在我的docker-compose.yml 文件中设置一个特定的环境变量。我认为我的docker-compose up 没有正确注册/读取它。
apigateway.web:
image: traefik
command: --api --docker # Enables the web UI and tells Traefik to listen to docker
environment:
- COMPOSE_CONVERT_WINDOWS_PATHS=1
ports:
- "80" # The HTTP port
- "8080" # The Web UI (enabled by --api)
volumes:
- /var/run/docker.sock:/var/run/docker.sock # So that Traefik can listen to the Docker events
我知道我可以将它设置在 .env 文件中。这不是基本一样吗?当然,.env 文件就像在我的docker-compose.yml 文件中的所有 服务中自动添加一个environment: 部分......与......只是为1 个服务设置该变量。但除此之外,它是同一件事,对吧?环境变量就是环境变量。
我之所以这样问,是因为当我将单个环境变量添加到该服务时,我不相信它会被“拾取/读取”,因为仍然会发生此错误:
Recreating 3ae831a08eab_dockercompose17057127240787984866_apigateway.web_1 ...
Recreating 3ae831a08eab_dockercompose17057127240787984866_apigateway.web_1 ... error
ERROR: for 3ae831a08eab_dockercompose17057127240787984866_apigateway.web_1 Cannot create container for service apigateway.web: b'Mount denied:\nThe source path "\\\\var\\\\run\\\\docker.sock:/var/run/docker.sock"\nis not a valid Windows path'
ERROR: for apigateway.web Cannot create container for service apigateway.web: b'Mount denied:\nThe source path "\\\\var\\\\run\\\\docker.sock:/var/run/docker.sock"\nis not a valid Windows path'
Encountered errors while bringing up the project..
这个错误似乎是talked about in this GitHub issue -> 答案是:添加环境变量COMPOSE_CONVERT_WINDOWS_PATHS=1。
注意事项:
- 我在 Windows 机器上。
- Docker 作为 Linux 容器运行。
所以——我是对的还是我在做的是完全错误的,我确实需要创建一个.env 文件,因为。
提前致谢!
【问题讨论】:
标签: docker docker-compose traefik