与docker-compose
says的文档相反,我无法在COMPOSE_PROJECT_NAME
文件中访问docker-compose.yml
的值。
$ cat docker-compose.yml
version: '3'
services:
web:
build: .
ports:
- "5000:5000"
environment:
- "PROJECT_NAME=${COMPOSE_PROJECT_NAME}"
redis:
image: "redis:alpine"
该变量未设置为默认值:
$ docker-compose config|grep PROJECT
WARNING: The COMPOSE_PROJECT_NAME variable is not set. Defaulting to a blank string.
PROJECT_NAME: ''
传入-p foobar
时也没有设置:
$ docker-compose -p foobar config|grep PROJECT
WARNING: The COMPOSE_PROJECT_NAME variable is not set. Defaulting to a blank string.
PROJECT_NAME: ''
将COMPOSE_NAME_PROJECT
定义为使用.env
文件或在环境中设置文件的唯一方法是什么?
答案 0 :(得分:0)
我只是在尝试相同的操作...似乎该变量不是要在compose-yaml中使用,而只是用于配置docker-compose CLI:
https://docs.docker.com/compose/reference/envvars/
您可以使用
很好地检查变量插值 docker-compose config