If you invoke docker-compose up -d and get error like this:

Error response from daemon: Conflict. The container name “/xyz” is already in use by container “…”. You have to remove (or rename) that container to be able to reuse that name.

then double-check if the name of the docker-compose project is not different.

If you didn’t explicitly specify env-var COMPOSE_PROJECT_NAME (or defined it in .env) then it will be derived from the directory name where the docker-compose.yml is located.

Assume you have a directory /home/piotr/some_name where the docker-compose.yml resides. You have started a container xyz using:

cd /home/piotr/some_name
docker-compose up -d

or

cd /home/piotr
docker-compose -f some_name/docker-compose.yml up -d

Then the docker-compose project will be set to some_name. The directory in which you were while invoking docker-compose does not matter.

You can inspect the name of the project by doing docker inspect xyz | grep com.docker.compose.project.

Now assume you want to update the version of the xyz container and start it again.

You update the version in /home/piotr/some_name/docker-compose.yml and run it as a part of wider docker-compose command like this:

cd /home/piotr
docker-compose up -f another-docker-compose.yml -f some_name/docker-compose.yml -d

You’ll get error saying that:

The container name “xyz” is already in use by container “…”. You have to remove (or rename) that container to be able to reuse that name.

That’s because the docker recognizes that the compose project (derived from another-docker-compose.yml location!) is different from the one the container is currently running.

To fix it, consider explicitly setting the COMPOSE_PROJECT_NAME env-var to the same value.