daemon: cleanupContainer: use state-fields instead of string form

This code only needed to know whether the container was paused; for other
states ("restarting", "running"), it's still used to be included in the
error string.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-05-08 19:42:27 +02:00
parent 4a00ce10fa
commit d44b2e4bd7

View File

@@ -88,10 +88,10 @@ func (daemon *Daemon) rmLink(cfg *config.Config, ctr *container.Container, name
func (daemon *Daemon) cleanupContainer(ctr *container.Container, config backend.ContainerRmConfig) error {
if ctr.IsRunning() {
if !config.ForceRemove {
if state := ctr.StateString(); state == "paused" {
return errdefs.Conflict(fmt.Errorf("cannot remove container %q: container is %s and must be unpaused first", ctr.Name, state))
if ctr.Paused {
return errdefs.Conflict(fmt.Errorf("cannot remove container %q: container is paused and must be unpaused first", ctr.Name))
} else {
return errdefs.Conflict(fmt.Errorf("cannot remove container %q: container is %s: stop the container before removing or force remove", ctr.Name, state))
return errdefs.Conflict(fmt.Errorf("cannot remove container %q: container is %s: stop the container before removing or force remove", ctr.Name, ctr.StateString()))
}
}
if err := daemon.Kill(ctr); err != nil && !isNotRunning(err) {