我正在尝试在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
文件就像在environment:
文件中自动向我的所有服务中添加docker-compose.yml
部分... vs ...只是设置该变量用于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
。
注意:
所以-我是对的还是我做的是完全错误的,实际上我确实需要创建一个.env
文件,因为。
提前谢谢!
答案 0 :(得分:0)
我相信您想在主机上设置COMPOSE_CONVERT_WINDOWS_PATHS = 1,以便docker-compose知道将Windows样式转换为Unix样式的卷定义。
$Env:COMPOSE_CONVERT_WINDOWS_PATHS = "1"
docker-compose up