Set $PROJECT_NAME in docker-compose file

I know this question was asked a long time ago, but I ran into the same problem. There's a suggestion to add the feature https://github.com/docker/compose/issues/745, but they don't want to.

However, I have a Makefile in the root of the directory and then you can add something like in the Makefile:

.PHONY: container-name
container-name:
    docker-compose -p $PROJECT_NAME up -d container-name

and then run make container-name

I know it isn't what you asked for, but could maybe make your life a bit easier.


220806 UPDATE: you can now use the top-level name property in your docker-compose YAML file.

This is the result of the #745 proposal.


UPDATE: You can now use the top-level name property in your docker-compose YAML file. This is available from Docker Compose v2.3.3

This is the result of the #745 proposal. An issue which persevered for about 8 years.

Previously: 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.