42

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!

1
  • I was facing the same issue and when i pass the "top" to my command it worked pretty well. What does that directive does? I couldn't find in the manuals. Thanks! Jun 16, 2017 at 15:23

3 Answers 3

53

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.

3
  • That was it. I actually figured it out late last night and was about to update. But thank you very much for taking a look and pointing it out.
    – Samar
    Sep 2, 2016 at 15:23
  • That little debug tip is super helpful
    – joshmcode
    Aug 21, 2017 at 15:28
  • 2
    To keep a container running and not doing much you can also use ``` docker run alpine tail -f /dev/null ``` It basically starts an alpine container and watching nothing (/dev/null). This will chew up minimal cpu. Running a container in "standby" is useful if you want to docker exec into it later to inspect volumes, network etc.
    – Bernard
    Aug 22, 2017 at 23:42
10

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.

0
1

In my case, the replicas were not working and a 0/0 was shown as I did not build them before.

As I saw here, when u publish to swarm with a docker-compose.yml you need to build them before

So, I decided to do a full system prune, and next to it, a build and a deploy (here, my stack was called demo and I did not have previous services or containers running):

docker stack rm demo 
docker system prune --all
docker-compose build
docker stack deploy -c ./docker-compose.yml demo

After this, all was up and running and now services replicas are up on swarm

PS C:\Users\Alejandro\demo> docker service ls
ID                  NAME                 MODE                REPLICAS            IMAGE               PORTS
oi0ngcmv0v29        demo_appweb          replicated          2/2                 webapp:1.0          *:80->4200/tcp
ahuyj0idz5tv        demo_express         replicated          2/2                 backend:1.0         *:3000->3000/tcp
fll3m9p6qyof        demo_fileinspector   replicated          1/1                 fileinspector:1.0   *:8080->8080/tcp

The way I maintain the replicas working, at the moment, in dev mode:

  • Angular/CLi app:

    command: >    
      bash -c "npm install && ng serve --host 0.0.0.0 --port 4200"
    
  • NodeJS Backend (Express)

    command: > 
      bash -c "npm install && set DEBUG=myapp:* & npm start --host 0.0.0.0 --port 3000"
    

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.