Docker Swarm Service - force update of latest image already running

Just for future reference:

Docker 1.13 added a --force flag to service update:

--force: Force update even if no changes require it

Use it as in:

docker service update --force service_name

Docker won't automatically perform a pull from DockerHub (or private registry) for an image:tag you already have locally.

If you performed a manual pull before the docker service update, or deleted the image locally, it would.

You could also chain the command:

docker pull image:tag && docker service update --image username/imagename:latest servicename

You can avoid this scenario by tagging your images numerically and using an updated tag. username/imagename:1.1.0


You could use image ID instead of username/imagename:latest like this:

docker service update --image \
$(docker inspect --type image --format '{{.Id}}' username/imagename:latest) \
servicename

But in this case all your nodes must pull this image before service update. Otherwise, containers will be updated only on those nodes where image with such ID exists. Fortunately, nodes which do not have this image will stop their containers, so there is nothing bad if some nodes will fail to pull new version of image.

UPDATE: or you could use image digest as follow:

docker service update --image \
$(docker inspect --type image --format '{{index .RepoDigests 0}}' username/imagename:latest) \
servicename

docker inspect --type image --format '{{index .RepoDigests 0}}' IMAGE returns image digest which includes unique hash of image generated by registry v2. Thus, image must be pulled from registry, otherwise digest will not be available.

Using digest allow you do not pull images on all of your nodes (images with specified digest will automatically be pulled from registry on necessary nodes). But you have to pull fresh version of image once on a manager node before service update.

BTW, last way will be default since Docker 1.13


If you want to update docker service image, you can simply do docker service update --image myimage:tag servicename. e.g. docker service update --image traefik:1.7.5 traefik_proxy Also by not using myimage:latest tag, it makes sure you will not unintentionally update to latest updated major/minor release instead of patch release.

Ref: https://github.com/moby/moby/issues/30951#issuecomment-279479589