Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I update the latest image that my docker service/stack uses?

In the .yml definition, I'm always pulling the latest image of my service.

When I push a new image to the registry and I want to update the image that the service in my stack uses. I don't see any --pull flag, and the documentation for docker service update doesn't explicitly mentions this.

How can I re-deploy using the recently pushed latest image?

like image 250
Christopher Francisco Avatar asked Jun 19 '18 20:06

Christopher Francisco


2 Answers

You really shouldn't use latest in production or anything beyond local machine testing/learning. It makes everything ambiguous as to which image you're using, and you can't tell in docker service ls/ps if it's current by default and all sorts of other ambiguities (like SHA's not being visible in Docker Hub's GUI).

If you have no way around it, at least Swarm tries to query your registry and check for an updated SHA. If it sees one with docker service update --image <username>/<repo> <servicename> then it will pull and do a rolling update. You can watch docker events to be sure things are happening, and you can use docker service ps --no-trunc <servicename> to check afterward and see the SHA hashes of old and new images.

like image 131
Bret Fisher Avatar answered Oct 31 '22 16:10

Bret Fisher


If you are using a compose file to deploy a service. I would not recommend using this command:

docker service update --image <username>/<repo> <servicename>    

This causes your file to be out of date and no longer the source of record for your service configuration. Instead, update your compose file with the specific image version, as Bret Fisher suggested, and run this command:

docker stack up -c </path/to/compose.yml> <servicename>

Keeping valid records is important if other people are also managing the swarm.

like image 28
D.Fitz Avatar answered Oct 31 '22 18:10

D.Fitz