Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restart a Docker service in global mode (non-replicated)?

In Docker Swarm mode, how can I restart a single global service? Is it even possible? I know you can scale replicated services to zero then back to 1+, but there doesn't appear to be any documentation on how to have the same effect with global services.

I am updating my SSL certificate so would like to just restart our reverse proxy instead of restarting our entire app (via restarting the docker service).

The docs just mention you cannot scale global services:

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.

like image 565
Nick Avatar asked Oct 15 '18 15:10

Nick


1 Answers

You can force a rolling update of a service, either globally scheduled or replicated using docker service update --force ${service_name}. Here's an example compose file:

version: '3'

services:
  busybox-global:
    image: busybox
    command: tail -f /dev/null
    deploy:
      mode: global

  busybox-replicated:
    image: busybox
    command: tail -f /dev/null
    deploy:
      replicas: 2

Verify it has started:

$ docker ps
CONTAINER ID        IMAGE                               COMMAND                  CREATED              STATUS      PORTS                            NAMES
917aefdc910b        busybox:latest                      "tail -f /dev/null"      50 seconds ago       Up 31 seconds                                       sched_busybox-global.q44zx0s2lvu1fdduk800e5ini.hzn6jnzh7x539timamphzzw8a
7187fbbde0da        busybox:latest                      "tail -f /dev/null"      About a minute ago   Up 31 seconds                                       sched_busybox-replicated.1.i4nm7lpr1spmf0aorh1dtcqrc
f04a0062b088        busybox:latest                      "tail -f /dev/null"      About a minute ago   Up 31 seconds                                       sched_busybox-replicated.2.oc6zn0ziqg9wyzofokek8eb24

$ docker service ls
ID                  NAME                       MODE                REPLICAS            IMAGE     PORTS
gto0d5a6betb        sched_busybox-global       global              1/1                 busybox:latest 
yfq5mne0qhtj        sched_busybox-replicated   replicated          2/2                 busybox:latest 

$ docker service ps sched_busybox-global
ID                  NAME                                             IMAGE               NODE                DESIRED STATE       CURRENT STATE            ERROR               PORTS
hzn6jnzh7x53        sched_busybox-global.q44zx0s2lvu1fdduk800e5ini   busybox:latest      bmitch-asusr556l    Running           Running 49 seconds ago

Force the rolling update:

$ docker service update --force sched_busybox-global
sched_busybox-global
overall progress: 1 out of 1 tasks
q44zx0s2lvu1: running   [==================================================>]
verify: Service converged

$ docker service ps sched_busybox-global                                
ID                  NAME                                                 IMAGE               NODE                DESIRED STATE       CURRENT STATE             ERROR               PORTS
zcfocrfjvvux        sched_busybox-global.q44zx0s2lvu1fdduk800e5ini       busybox:latest      bmitch-asusr556l    Running             Running 7 seconds ago
hzn6jnzh7x53         \_ sched_busybox-global.q44zx0s2lvu1fdduk800e5ini   busybox:latest      bmitch-asusr556l    Shutdown            Shutdown 10 seconds ago

$ docker ps -a
CONTAINER ID        IMAGE                               COMMAND                  CREATED              STATUS                            PORTS                            NAMES
3c5fe0f79e3d        busybox:latest                      "tail -f /dev/null"      About a minute ago   Up About a minute                                                  sched_busybox-global.q44zx0s2lvu1fdduk800e5ini.zcfocrfjvvuxz6tkge0pn0bq2
917aefdc910b        busybox:latest                      "tail -f /dev/null"      3 minutes ago        Exited (137) About a minute ago                                    sched_busybox-global.q44zx0s2lvu1fdduk800e5ini.hzn6jnzh7x539timamphzzw8a
7187fbbde0da        busybox:latest                      "tail -f /dev/null"      3 minutes ago        Up 2 minutes                                                       sched_busybox-replicated.1.i4nm7lpr1spmf0aorh1dtcqrc
f04a0062b088        busybox:latest                      "tail -f /dev/null"      3 minutes ago        Up 2 minutes                                                       sched_busybox-replicated.2.oc6zn0ziqg9wyzofokek8eb24

The same would have worked if I forced an update to the replicated service.

like image 164
BMitch Avatar answered Nov 15 '22 06:11

BMitch