在docker-compose文件中设置$ PROJECT_NAME

问题描述:

我在多个项目中使用相同的 docker-compose.yml 文件。我真的很懒,所以我不想以 docker-compose -p $ PROJECT_NAME up 开始。

I am using the same docker-compose.yml file for multiple projects. I am really lazy, so I don't want to start them with docker-compose -p $PROJECT_NAME up.

从Docker 17.06.0版开始,是否可以直接在 docker-compose.yml 文件中设置变量?

As of Docker version 17.06.0, is it possible to set the variable directly in the docker-compose.yml file?

现在,我们可以使用 .env 文件以设置自定义项目名称,如下所示:

Right now, we can use the .env file to set the custom project name like this:

COMPOSE_PROJECT_NAME=SOMEPROJECTNAME

它不灵活,但总比没有好。当前,有有关此提案的公开问题

It's not flexible, but it's better than nothing. Currently, there is an open issue regarding this as a proposal.