What’s the Right Way to Update a Docker Swarm Service?

0
7
Asked By ChillPanda42 On

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

Answered By ContainerEnthusiast On

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.

Answered By TechieGuru91 On

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.

QuickFixer88 -

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

SuccessStory32 -

I tried using timestamps in my tagging, and it worked perfectly! So much easier.

Answered By CodeWhisperer99 On

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.

DevNinja77 -

Absolutely! The stack deploy command translates tags to digests, ensuring it updates when needed. The service update doesn't have that capability.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.