vfarcic / vfarcic.github.io

MIT License
148 stars 115 forks source link

Rolling updates with update_config:order: start-first | stop-first #13

Closed dipanjanmukherjee83 closed 5 years ago

dipanjanmukherjee83 commented 5 years ago

From docker compose file version 3.4 and above we can change the default behaviour of container spin-up during service update by using "order: start-first | stop-first" in “update_config” section.By default the Update order is "stop-first". And as per the docker docs with "start-first", the new task is started first, and the running tasks briefly overlap. Now my question is, we have a Global mode service running and if we add this option in stack file how at the same time both the containers will access the same port. Because as per our understanding when the new task or container become ready in our case curl that port then old task or container will be shutdown. So at one moment there would be port conflict happened. Or the theory is different.

vfarcic commented 5 years ago

Ports are not opened in containers directly. Instead, Overlay network receives requests and forwards them to one of the associated containers using the round-robin algorithm. So, it does not matter how many containers of a service run at the same time. The requests are distributed to all of them.

dipanjanmukherjee83 commented 5 years ago

True. But my question was for Global mode service where one instance will run at a time. So what is the theory happened behind it.

vfarcic commented 5 years ago

The logic is still the same with Global services. Their traffic is controlled with Overlay network. The only significant difference is that a replica runs on each node, instead Swarm distributing them based on resource usage.

dipanjanmukherjee83 commented 5 years ago

Hi @vfarcic, We are using global mode with host networking and we have tested the "start-first" order option is not working and in my opinion theoretically it is not possible. During service update it stuck and showing "host-mode port already in use on 1 node". If you use host mode, the port is only bound on nodes where the service is running, and a given port on a node can only be bound once. But thanks anyway.

vfarcic commented 5 years ago

Now I get it. I did not know (until now) that host networking is involved. Unfortunately, I never used it myself (beyond simple experiments) so I can't answer the question based on experience.