问题
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
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/43182942/docker-service-update-vs-docker-stack-deploy-with-existing-stack