Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop/start docker containers in swarm mode without removing?

I am new in docker swarm mode. As you know it possible to start/stop docker container but i see no possibility to do this in swarm.
For example, I've deployed swarm and created new tasks with replica(2/2):

docker service ls
ID                  NAME                MODE                REPLICAS            IMAGE                                                                               PORTS
2o3a6z30q9df        contactactivity     replicated          2/2                 myimage/live-springboot-myservice:19ff0be1f0087asd1dasdb52c345151e9985b4a5a2   *:111->1111/tcp

Is it possible to stop one of the swarm containers without removing it and bring it back in future?

P.S. I am just want to clarify that remove or recreate - is not the option in my case.

To make Q clear: If you stop container and then start - this container wont be a part of swarm. I cannot believe that in swarm mode there is no way to do simple restart or start/stop.

like image 247
Sergey Gorshkov Avatar asked Aug 03 '17 09:08

Sergey Gorshkov


People also ask

How do I stop docker from running in swarm mode?

Run the docker swarm leave command on a node to remove it from the swarm. For example to leave the swarm on a worker node: $ docker swarm leave Node left the swarm. When a node leaves the swarm, the Docker Engine stops running in swarm mode.

How do I stop docker container and start again?

The syntax is simple: $ docker stop [OPTIONS] CONTAINER [CONTAINER...] You can specify one or more containers to stop. The only option for docker stop is -t (–time) which allows you to specify a wait time before stopping a container.

Does docker swarm restart container?

Updating the existing service, swarm will recreate all containers. For example, you can simply update a property of the service to archive restarting.


1 Answers

List the containers running for the service & stop them for example docker ps | grep service-name and then stop the container by using docker stop <ID> from above command.

                                 OR

If you want to stop all containers then just scale down the service to 0 like below docker service scale servicename=0 bring them back using docker service scale servicename=N

like image 85
Harshad Yeola Avatar answered Oct 19 '22 21:10

Harshad Yeola