-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Scale down sorts by obsolete status but stops/removes containers in the reverse order #11781
Comments
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This issue has been automatically marked as not stale anymore due to the recent activity. |
nope, there's no reason the older is removed as long as both match the service configuration. Having container running for a longer time doesn't mean it's obsolete and a "fresh new one" would perform better (in many cases, this is actually the opposite with JIT compiler / runtime optimisation) Is there a specific use-case that would require a distinct logic ? |
Interesting and fair! From the initial report (and also why I subscribed) removing the older container would be perfect for rolling updates. That's at least personally the only reason I'd consider running Swarm on a single machine. Maybe a CLI option would suffice if the existing behavior is still valuable. And even creating container names from missing indices instead of the next one up, although again personally I wouldn't mind at all. Forgive my ignorance if I've missed any details though, and thank you for the awesome tool you have provided! |
Rolling updates is the main reason. I should clarify the purpose of the ticket as it may not be clear i'm referring to the newer version of an image being disposed of instead of the previous version. I absolutely agree it shouldn't just be used to replace a container running the same image, as it's better to use the older container if it's still valid, we can force a recreation for that if needed. The previous changes to the logic mean it's no longer just going by createdDate but checks if any of the containers running are obsolete (due to them being an older version of the image etc), which is great, but the logic puts the obsolete container first. Later in the code it looks like it's then using a for loop and once the index is over the count of expected containers, it begins removing them, meaning the obsolete container remains and the valid one gets removed. If i have two containers that used the same image tag (latest):
It sorts them by placing them in order [Container1, Container2] (obsolete first, then non-obsolete second), performs a for loop, the first is within our desired scale of 1, then the second is removed. The sorting i think just needs to be reversed so we have valid first, obsolete last. |
rolling upgrade means image has been updated, and as such container should be detected not to be up-to-date and will be re-created |
If i use When scaling down, the out-of-date instance is now the obsolete one. |
As you're basically bypassing compose logic intentionally, don't be surprised the result is not consistent with your expectations. What you're looking for is for compose to have an actual rolling upgrade policy to update obsolete containers. Please fill a feature request for this purpose |
let me double check. |
you're right, I created #12272 to cover this scenario |
Thanks! Appreciate the fix |
Description
This was initially logged in #11460 but only part of it was fixed. The fix applied by #11473 does prevent scale down recreating a container incorrectly, however it didn't solve the issue of the container sorting being wrong when finding which ones need to be removed to scale down.
If I scale up to 2 instances, then scale down to 1, the newest container is the one that's removed instead of the oldest. This causes an issue if you use scale up with no-recreate to deploy the new version of an image, then use scale down to get rid of the old one. Currently the newest gets removed so you're left with the old version of an image running.
The old sort logic before #11473:
The new sort logic after #11473:
The loop following:
So more logic is added to check which containers are obsolete which is great, as well as then going by date created, but the order we remove them in is still wrong. Obsolete/old containers are first in the list, but when looping and scaling down the containers first in the list are treated as valid, we instead get rid of those lower down in the list of containers i believe.
Steps To Reproduce
docker compose up -d --scale (service-name)=2 --no-recreate
, which will launch another container for the same service.docker compose up -d --scale (service-name)=1 --no-recreate
Even if the image used for container 2 is newer, it'll still remove container 2 first, leaving the older image in container 1 running.
Compose Version
Docker Environment
Anything else?
No response
The text was updated successfully, but these errors were encountered: