Reputation: 380
I am developing a service using docker-compose and I deploy the the containers to a remote host using this commands:
eval $(docker-machine env digitaloceanserver)
docker-compose build && docker-compose stop && docker-compose rm -f && docker-compose up -d
My problem is that I'm changing laptop and I exported the docker-machines to the new laptop and I can activate them. But when I try to deploy new changes it raises these errors:
Creating postgres ... error Creating redis ...ERROR: for postgres Cannot create container for service postgres: b'Conflict. The container name "/postgres" is already in use by container "612f3887544224aeCreating redis ... errorERROR: for redis Cannot create container for service redis: b'Conflict. The container name "/redis" is already in use by container "01875947f0ce7ba3978238525923e54e0c800fa0a4b419dd2a28cc07c285eb78". You have to remove (or rename) that container to be able to reuse that name.'ERROR: for postgres Cannot create container for service postgres: b'Conflict. The container name "/postgres" is already in use by container "612f3887544224ae79f67e29552b4d97e246104b8a057b3a03d39f6546dbbd38". You have to remove (or rename) that container to be able to reuse that name.'ERROR: for redis Cannot create container for service redis: b'Conflict. The container name "/redis" is already in use by container "01875947f0ce7ba3978238525923e54e0c800fa0a4b419dd2a28cc07c285eb78". You have to remove (or rename) that container to be able to reuse that name.' ERROR: Encountered errors while bringing up the project.
My docker-compose.yml is this:
services:
nginx:
build: './docks/nginx/.'
ports:
- '80:80'
- "443:443"
volumes:
- letsencrypt_certs:/etc/nginx/certs
- letsencrypt_www:/var/www/letsencrypt
volumes_from:
- web:ro
depends_on:
- web
letsencrypt:
build: './docks/certbot/.'
command: /bin/true
volumes:
- letsencrypt_certs:/etc/letsencrypt
- letsencrypt_www:/var/www/letsencrypt
web:
build: './sources/.'
image: 'websource'
ports:
- '127.0.0.1:8000:8000'
env_file: '.env'
command: 'gunicorn cuidum.wsgi:application -w 2 -b :8000 --reload --capture-output --enable-stdio-inheritance --log-level=debug --access-logfile=- --log-file=-'
volumes:
- 'cachedata:/cache'
- 'mediadata:/media'
depends_on:
- postgres
- redis
celery_worker:
image: 'websource'
env_file: '.env'
command: 'python -m celery -A cuidum worker -l debug'
volumes_from:
- web
depends_on:
- web
celery_beat:
container_name: 'celery_beat'
image: 'websource'
env_file: '.env'
command: 'python -m celery -A cuidum beat --pidfile= -l debug'
volumes_from:
- web
depends_on:
- web
postgres:
container_name: 'postgres'
image: 'mdillon/postgis'
ports:
- '127.0.0.1:5432:5432'
volumes:
- 'pgdata:/var/lib/postgresql/data/'
redis:
container_name: 'redis'
image: 'redis:3.2.0'
ports:
- '127.0.0.1:6379:6379'
volumes:
- 'redisdata:/data'
volumes:
pgdata:
redisdata:
cachedata:
mediadata:
staticdata:
letsencrypt_certs:
letsencrypt_www:
Upvotes: 0
Views: 1086
Reputation: 159555
You’re seeing those errors because you’re explicitly setting container_name:
, and those same container names are used elsewhere. Remove those explicit settings. (You don’t need them even for inter-container DNS; Docker Compose automatically creates an alias for you using the name of the service block.)
There are still potential issues from port conflicts. If your other PostgreSQL container is listening on the same (default) host port 5432 then the one you declare in this docker-compose.yml
file will conflict with it. You might be able to just not expose your database container ports, or you might need to change the port numbers in this file.
Upvotes: 1