Docker Swarm Service - force update of latest image already running Docker Swarm Service - force update of latest image already running docker docker

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