Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker Cannot start service as already exists

Running docker-compose up -d I got the following error:

Starting cr-redis ... 
Starting cr-rabbitmq ... 
Starting cr-rabbitmq ... error

Starting cr-redis ... error

Starting cr-mysql ... error

ERROR: for cr-mysql  Cannot start service mysql: container "ff36...1116": already exists

ERROR: for rabbitmq  Cannot start service rabbitmq: container "3b6c...0aba": already exists

ERROR: for redis  Cannot start service redis: container "e84f...df91": already exists

ERROR: for mysql  Cannot start service mysql: container "ff36...1116": already exists
ERROR: Encountered errors while bringing up the project.


docker-compose ps   
     Name                    Command                State                                    Ports                                
----------------------------------------------------------------------------------------------------------------------------------
cr-mysql       docker-entrypoint.sh mysqld      Exit 255                                                                       
cr-php-fpm     /bin/sh -c /usr/sbin/php-f ...   Exit 255   9000/tcp                                                            
cr-rabbitmq    docker-entrypoint.sh rabbi ...   Exit 255                                                                       
cr-redis       docker-entrypoint.sh redis ...   Exit 255                                                                       
cr-webserver   nginx -g daemon off;             Exit 255   0.0.0.0:15672->15672/tcp, 0.0.0.0:80->80/tcp, 0.0.0.0:9003->9003/tcp

How can I start again the container without recreating it? I just don't want to lose the data in the DB.

--------------- UPDATE --------------------

$ docker-compose stop
$ docker-compose start
Starting redis     ... error
Starting rabbitmq  ... error
Starting mysql     ... error
Starting php-fpm   ... error
Starting webserver ... error

ERROR: for rabbitmq  Cannot start service rabbitmq: container "3b6c...0aba": already exists

ERROR: for mysql  Cannot start service mysql: container "ff36...1116": already exists

ERROR: for redis  Cannot start service redis: container "e84f...f91": already exists
ERROR: No containers to start
like image 878
Luigi T. Avatar asked Sep 10 '25 00:09

Luigi T.


1 Answers

Your case is probably related to a bug that will be fixed in the 18.03 release. Some workarounds are proposed here:

  • https://github.com/docker/for-linux/issues/211
  • https://github.com/moby/moby/issues/36145

docker-compose up builds, (re)creates, starts, and attaches to containers for a service.

Since your images are built and the containers of your service have started, you can then use

  • docker-compose stop and
  • docker-compose start

to start/stop your service. This is different from docker-compose down which:

Stops containers and removes containers, networks, volumes, and images created by up.


Regarding the danger of losing your data if a container is removed, read about persistent storage and how to use volumes.

like image 65
tgogos Avatar answered Sep 13 '25 02:09

tgogos