使用默认值时访问COMPOSE_PROJECT_NAME

时间:2017-12-20 13:50:30

标签: docker docker-compose

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文件或在环境中设置文件的唯一方法是什么?

1 个答案:

答案 0 :(得分:0)

我只是在尝试相同的操作...似乎该变量不是要在compose-yaml中使用,而只是用于配置docker-compose CLI:

https://docs.docker.com/compose/reference/envvars/

您可以使用

很好地检查变量插值

docker-compose config