I have a docker-compose stack launched on a remote machine, through gitlab CI/CD (a runner connects to the docker engine on the remote machine and performs the deploy with docker-compose up -d
).
When I connect to that machine from my laptop, using eval docker-machine env REMOTE_ADDRESS
, I can see the docker processes running (with docker ps
), while the services stack appears to be empty (docker-compose ps
).
I am not able to use docker-compose down
to stop the stack, and trying docker-compose up -d
gives me the error
ERROR: for feamp_postgres Cannot create container for service postgres: Conflict. The container name "/feamp_postgres" is already in use by container "40586885...". You have to remove (or rename) that container to be able to reuse that name.
The reverse is also true, I can start the stack from my local laptop (using docker-machine), but then the CI/CD pipeline fails when trying to execute docker-compose up -d
with the same error.
This happens using the latest versions of docker and docker-compose, both on the laptop (OSX) and on the runner (ubuntu 18.04).
In other circumstances (~10 other projects) this has worked smoothly.
This is the docker-compose.yml
file I am using.
version: "3.7"
services:
web:
container_name: feamp_web
restart: always
image: guglielmo/fpa/feamp:latest
expose:
- "8000"
links:
- postgres:postgres
- redis:redis
environment:
- ...
volumes:
- public:/app/public
- data:/app/data
- uwsgi_spooler:/var/lib/uwsgi
- weblogs:/var/log
command: /usr/local/bin/uwsgi --socket=:8000 ...
nginx:
container_name: feamp_nginx
restart: always
...
postgres:
container_name: feamp_postgres
restart: always
image: postgres:11-alpine
...
redis:
container_name: feamp_redis
restart: always
image: redis:latest
...
volumes:
...
networks:
default:
external:
name: webproxy
Normally I can up the stack from my local laptop and manage it from the CI/CD pipeline on gitlab, or vice-versa.
This diagram should help visualise the situation.
+-----------------+
| |
| Remote server |
| |
+----|--------|---+
| |
| |
docker-compose ps| |docker-compose up -d
| |
| |
+-------------------+ | | +--------------------+
| | | | | |
| Docker client 1 ---------+ +--------- Docker client 2 |
| | | |
+-------------------+ +--------------------+
Connection to the remote server's docker engine are executed through docker-machine
.
It appears that specifying the project name when invoking docker-compose
commands, solves the issue.
This can be done using the -p
parameter in the command line or the COMPOSE_PROJECT_NAME
environment variable, on both clients.
For some reasons, this was not needed in previous projects. It may be a change in docker (I changed from 18 to 19), or something else, I still do not know the details.
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