Docker无法启动已存在的服务

时间:2018-03-14 12:38:32

标签: docker docker-compose containers

正在运行docker-compose up -d我收到以下错误:

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

如何在不重新创建容器的情况下重新启动容器?我只是不想丢失数据库中的数据。

---------------更新--------------------

$ 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

2 个答案:

答案 0 :(得分:4)

您的案例可能与将在18.03版本中修复的错误有关。这里提出了一些解决方法:

  

docker-compose up构建,(重新)创建,启动和附加服务的容器。

由于您构建了images并且服务的containers已经开始,您可以使用

  • docker-compose stop
  • docker-compose start

开始/停止您的服务。这与docker-compose down不同,后者:

  

停止容器并移除由up创建的容器,网络,卷和图像。

关于删除容器时丢失数据的危险,请阅读持久存储以及如何使用

答案 1 :(得分:2)

您需要使用docker-compose start代替:

$ docker-compose start --help
Start existing containers.

Usage: start [SERVICE...]