I'm using Docker Swarm on a single machine for seamless updates to my website. Here's what I do: I publish a new Docker image with the tag 'latest' from my development machine, then on the server, I run 'docker pull myimage:latest'. However, I notice that the running container changes from 'latest' back to the previous image's hash. Then I execute 'docker service update --image myimage:latest myservicename'. The console indicates that the service has converged, yet my old container continues running and the latest image is marked as 'Unused'. I expected Docker to start the new container and redirect requests to it, but that doesn't happen. What am I doing wrong?
3 Answers
You might want to look into using the '--force' option when updating the service. This forces the recreation of the containers and should switch it to the current image.
It seems like you're hitting a common issue with Docker Swarm. The thing is, when you update the service with the same 'latest' tag, Docker doesn't recognize any changes because the service definition hasn't changed. To get around this, avoid using the 'latest' tag. Instead, use unique tags, like version numbers or timestamps, so Docker knows to pull the new image. This way, you'll ensure the service updates correctly.
I tried using timestamps in my tagging, and it worked perfectly! So much easier.
One alternative is to use 'docker stack deploy'. It automatically fetches the right image and will restart the service whenever necessary, even if you're using 'latest'. This means it won't do anything if there's no new image, so it's definitely a better option than a plain service update.
Absolutely! The stack deploy command translates tags to digests, ensuring it updates when needed. The service update doesn't have that capability.

Exactly! Using version tags not only helps in updates but also makes rollback much simpler.