What’s the Best Way to Update a Service in Docker Swarm Without Downtime?

0
8
Asked By TechWizard88 On

I'm currently using Docker Swarm on a single machine to perform no-downtime updates for my website. Here's my process:

1. I publish a new Docker image tagged as "latest" from my dev machine.
2. On the server, I run "docker pull myimage:latest" but notice that my running container's image changes from "latest" to the previous image's hash.
3. Then, I execute the command "docker service update --image myimage:latest myservicename" and the console shows:

overall progress: 1 out of 1 tasks
1/1: running [==================================================>]
verify: Service myservicename converged

In Portainer, I see that my service has been updated to the latest version of the container, but Docker doesn't attempt to stop the old container or restart the new one. The old container remains running, and the latest image shows as "Unused." I expected Docker to start a new container and redirect traffic to it. What am I missing?

3 Answers

Answered By DevNinja92 On

If you want a quick workaround, you can use the `--force` option with your update command. This will force Docker to recreate the containers and, in doing so, switch them to the latest image.

Answered By ServerGuru23 On

Another option to consider is using `docker stack deploy`, which will automatically fetch the correct image and restart the service if necessary, even when using the "latest" tag. It ensures that the deployment reflects the latest updates in your images.

Answered By DockerExpert01 On

It looks like the issue stems from using the "latest" tag for your images. Docker Swarm doesn't recognize that there's an actual change in the service definition because both the old and new images are tagged as "latest." Ideally, you should use unique tags for your images, like version numbers or timestamps, which will help Docker realize that there’s a new image to pull and deploy.

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.