Docker Swarm - Zero Downtime

Hi there, in our Docker swarm, we are creating services using the below commands, but while removing and creating services, we are facing downtime.

sudo docker build . -t example:0.0.1 --build-arg
sudo docker tag fees:0.0.1 localhost:5000/example:0.0.1
sudo docker push localhost:5000/example:0.0.1
docker service rm example-service
sudo docker service create --name example-service --replicas 6 --replicas-max-per-node 1 --publish published=3000,target=80,mode=host --constraint ‘node.labels.worker==true’ --network network-one --endpoint-mode dnsrr localhost:5000/example:0.0.1

Can you please suggest any solutions!!!

Used the docker update command, but because of host mode, we are getting port conflicts. Can’t you use ingress mode, as it needs extensive setup with traffic routing and nginx. Are there any other ways which I can try

If you use docker service rm, then the service is removed, all containers, too.

Use docker service update, check the tutorial and the doc, probably use --update-order=stop-first and add --update-delay.

Our services do not expose ports on host, instead Traefik proxy and a Docker Swarm overlay network is used. So no port conflicts.

I tried to use the Docker service update command, but got errors because of Port conflicts and cause of host mode. Can’t really use ingress mode as it will take extensive setup as a Load balancer and reverse proxy setup

You need to shut down the old container first, as I wrote:

Regarding Zero downtime, it is not clear what your setup is, how many workers you have, and I’m not a Swarm user (I use Kubernetes), so I don’t remember how scheduling works exactly in Docker Swarm, but in general, you will not have zero downtime on a single node or if yo can’t make sure your new instance is started on a new node, when you are using the host mode