10

I have a doubt in using docker swarm mode commands to update existing services after having deployed a set of services using docker stack deploy. As far I understood every service is pinned to the SHA256 digest of the image at the time of creation, so if you rebuild and push an image (with same tag) and you try to run a docker service update, service image is not updated (even if SHA256 is different). On the contrary, if you run a docker stack deploy again, all the services are updated with the new images. I managed to update the service image also by using docker service update --image repository/image:tag <service>. Is this the normal behavior of these commands or is there something I didn't understood?

I'm using Docker 17.03.1-ce

Alessandro Dionisi
  • 2,494
  • 4
  • 33
  • 37

2 Answers2

5

Docker stack deploy documentation says: "Create and update a stack from a compose or a dab file on the swarm. This command has to be run targeting a manager node." So the behaviour you described is as expected.

Docker service update documentation is not so clear but you yourself said it only runs with --image repository/image:tag <service> so the flag is necessary to update the image.

You have two ways to accomplish what you want.

herm
  • 14,613
  • 7
  • 41
  • 62
  • I just want to understand if it is normal that `docker stack deploy` updates existing services or it is a bug instead. – Alessandro Dionisi Apr 03 '17 at 12:12
  • The documentation states that stack deploy is to create and update a stack. So it's not a bug it's a feature :) – herm Apr 03 '17 at 12:29
  • Clearly, I'm not talking about the fact that `docker stack deploy` updates the stack, rather about the fact that it also updates image digests, compared to plain `docker service update`. – Alessandro Dionisi Apr 03 '17 at 17:03
  • 1
    Your compose file describes what images you use. If you don't specify a tag docker will decide which image to use for you. And as far as I know it always uses the latest. To me it is clear that it would behave like this. The documentation states that it updates the stack and I assume its according to the description in your file – herm Apr 03 '17 at 19:11
2

It is normal and expected behavior for docker stack deploy to update images of existing services to whatever hash the specified tag is linked.

If no tag is present, latest is assumed - which can be problematic at times, since the latest tag is not well understood by most persons, and thus lead to some unexpected results.

demaniak
  • 3,716
  • 1
  • 29
  • 34
  • can you indicate some article to understand better the latest tag or explain about it? thanks. – Marco Blos Feb 16 '18 at 22:19
  • 1
    Hi @MarcoBlos , you can start with these: https://medium.com/@mccode/the-misunderstood-docker-tag-latest-af3babfd6375 , http://container-solutions.com/docker-latest-confusion/ . – demaniak Feb 20 '18 at 13:03
  • 1
    Thanks @demaniak. There are more information about this problem in this question now. – Marco Blos Feb 20 '18 at 18:58