profile
viewpoint

Ask questionsrestart option for docker services (1.12 swarm mode)

It would be useful to have "docker service restart" command (docker 1.12 swarm mode):

docker service --help

Usage:  docker service COMMAND

Manage Docker services

Options:
      --help   Print usage

Commands:
  create      Create a new service
  inspect     Display detailed information on one or more services
  tasks       List the tasks of a service
  ls          List services
  rm          Remove a service
  scale       Scale one or multiple services
  update      Update a service

Proposal to add: restart Restart a service (possibly also start & stop?)

Currently restart can be achieved using update command and making some small change, e.g. environment variable:

docker service create --name nginxtest --replicas 5  nginx:alpine

...

docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
a423e652d7aa        nginx:alpine        "nginx -g 'daemon off"   2 minutes ago       Up 2 minutes        80/tcp, 443/tcp     nginxtest.2.9ovt80inulc83dx54s44abwcl
03d0fd19495c        nginx:alpine        "nginx -g 'daemon off"   2 minutes ago       Up 2 minutes        80/tcp, 443/tcp     nginxtest.3.2p6i7koib4jyft8hjm040n4r9
f4fd7037ca64        nginx:alpine        "nginx -g 'daemon off"   2 minutes ago       Up 2 minutes        80/tcp, 443/tcp     nginxtest.1.5icr2v7lo4bc1gmfeugjaeafb
56c1885c48ff        nginx:alpine        "nginx -g 'daemon off"   2 minutes ago       Up 2 minutes        80/tcp, 443/tcp     nginxtest.5.5t72qvz1he48azymoo7w1s83y
03ff0eda8a8d        nginx:alpine        "nginx -g 'daemon off"   2 minutes ago       Up 2 minutes        80/tcp, 443/tcp     nginxtest.4.32ze8c6s2pr9ogvc9i6a84qak

...

docker service update nginxtest -e TEST:foo
nginxtest

docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                  PORTS               NAMES
6061a6e89733        nginx:alpine        "nginx -g 'daemon off"   2 seconds ago       Up Less than a second   80/tcp, 443/tcp     nginxtest.1.awphkdsvuwbifayvbzvyy8cju
d827eeeb1826        nginx:alpine        "nginx -g 'daemon off"   2 seconds ago       Up Less than a second   80/tcp, 443/tcp     nginxtest.5.2dfooji7rjdjzuahfbx880p5z
fd17d1d87e50        nginx:alpine        "nginx -g 'daemon off"   2 seconds ago       Up Less than a second   80/tcp, 443/tcp     nginxtest.4.1b1a9pn67zlf9cfmz5s2q2j6x
fdc87806ce6a        nginx:alpine        "nginx -g 'daemon off"   2 seconds ago       Up Less than a second   80/tcp, 443/tcp     nginxtest.3.cz797anjh5kqrexa5m2wntj27
36943cef6abd        nginx:alpine        "nginx -g 'daemon off"   2 seconds ago       Up Less than a second   80/tcp, 443/tcp     nginxtest.2.323q7w45ycoe01xdmlnnjn9sd

However update with no changes does nothing, and setting only one env variable can remove existing ones so this option does not feel quite right.

Update also (from my limited understanding) removes the actual container and creates a new one, in order to allow new settings to be applied. Restart should simply restart the container without removing and recreating it.

Workaround is to read tasks list and iterate over containers, issuing restart to individual hosts and containers, but it would be more convenient to restart via swarm.

moby/moby

Answer questions williamwebb

docker service ls -q | xargs -t -n1 docker service update --force should work to restart all services at once.

Related questions

start container failed with "failed to umount /var/lib/docker/containers/.../shm: no such file or directory" hot 47
upgrade docker-18.09.2-ce , shim.sock: bind: address already in use: unknown hot 24
start container failed with "failed to umount /var/lib/docker/containers/.../shm: no such file or directory" hot 17
runc regression - EPERM running containers from selinux hot 11
Windows Server 2019 publish ports in swarm not working hot 11
"docker stack deploy">"rpc error: code = 3 desc = name must be valid as a DNS name component" hot 9
OCI runtime exec failed: exec failed: cannot exec a container that has stopped: unknown hot 8
Swarm restarts all containers hot 8
integration: "error reading the kernel parameter" errors during CI hot 8
hcsshim::PrepareLayer failed in Win32: The parameter is incorrect hot 8
Docker 18.09.1 doesn't work with iptables v1.8.2 hot 7
Error response from daemon: rpc error: code = DeadlineExceeded desc = context deadline exceeded hot 6
Containers on overlay network cannot reach other containers hot 6
write unix /var/run/docker.sock->@: write: broken pipe hot 6
feature request: docker cat command hot 6
Github User Rank List