Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker service replicas remain 0/1

I am trying out docker swarm with 1.12 on my Mac. I started 3 VirtualBox VMs, created a swarm cluster of 3 all fine.

docker@redis1:~$ docker node ls  ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS 2h1m8equ5w5beetbq3go56ebl    redis3  Ready Active  8xubu8g7pzjvo34qdtqxeqjlj    redis2  Ready Active Reachable  cbi0lyekxmp0o09j5hx48u7vm *  redis1  Ready Active Leader 

However, when I create a service, I see no errors yet replicas always displays 0/1:

docker@redis1:~$ docker service create --replicas 1 --name hello ubuntu:latest /bin/bash 76kvrcvnz6kdhsmzmug6jgnjv docker@redis1:~$ docker service ls ID            NAME   REPLICAS  IMAGE          COMMAND 76kvrcvnz6kd  hello  0/1       ubuntu:latest  /bin/bash docker@redis1:~$ docker ps CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES 

What could be the problem? Where do I look for logs? Thanks!

like image 570
Samar Avatar asked Sep 02 '16 04:09

Samar


People also ask

What are docker replicas?

A replicated service is a Docker Swarm service that has a specified number of replicas running. These replicas consist of multiple instances of the specified Docker container. In our case, each replica will be a unique Redis instance.

What is the docker command to increase number of replicas?

The scale command enables you to scale one or more replicated services either up or down to the desired number of replicas. This command cannot be applied on services which are global mode. The command will return immediately, but the actual scaling of the service may take some time.

What are the two types of docker swarm services?

Swarm mode has two types of services: replicated and global. For replicated services, you specify the number of replica tasks for the swarm manager to schedule onto available nodes.


2 Answers

The problem is that your tasks (calling bin/bash) exits quickly since it's not doing anything.

If you look at the tasks for your service, you'll see that one is started and then shutdown within seconds. Another one is then started, shutdown and so on, since you're requested that 1 task be running at all times.

docker service ps hello 

If you use ubuntu:latest top for instance, the task will stay up running.

like image 129
Bernard Avatar answered Sep 27 '22 22:09

Bernard


This also can happen if you specify a volume in your compose file that is bound to a local directory that does not exist.

If you look at the log (on some Linux systems, this is journalctl -xe), you'll see which volume can't be bound.

like image 27
Jim Hunziker Avatar answered Sep 27 '22 22:09

Jim Hunziker