I have a set of docker that I run using docker-compose up -d
pretty basic so far
I want to run multiple instances of my project and I have read this Run multiple docker compose
Now when running docker-compose up -p PRNAME -d
compose is not prepending project name to containers like prname_container1
and I'm getting the following error :
ERROR: for container1 Cannot create container for service service1: Conflict. The container name "/container1" is already in use by container "f7aeb2ef782556ae5b0". You have to remove (or rename) that container to be able to reuse that name.
I might be missing something out here.
A part of my docker-compose.yml looks like
services:
service1:
image: "${PROJECT_REPO}:image"
container_name: "container1"
ports:
- 443:443
- 8000:80
networks:
- db
- proxy
- oauth
depends_on:
- db
When you explicitly set container_name:
in your docker-compose.yml
file, the container name will be exactly what you specify; Docker Compose won't add its per-directory prefix to it.
Usually this doesn't matter to you at all, and it's safe to remove container_name:
. You will still be able to reach other containers using their service name in docker-compose.yml
as hostnames, and the docker-compose
CLI provides wrappers for management commands like docker-compose stop
that will act on the correct container.
You will also hit trouble with ports:
and there is less of a clear solution here. Only one container or process can bind to a specific port on the host. You can leave off the first port number in ports:
, and Docker will pick a port for you
ports:
- '80'
- '443'
but then you need to manually look up the corresponding host port number
docker-compose port service1 80
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With