diff --git a/daemon/container.go b/daemon/container.go index 4e5551370f..9837b7b189 100644 --- a/daemon/container.go +++ b/daemon/container.go @@ -437,7 +437,23 @@ func (container *Container) Kill() error { // 1. Send SIGKILL if err := container.killPossiblyDeadProcess(9); err != nil { - return err + // While normally we might "return err" here we're not going to + // because if we can't stop the container by this point then + // its probably because its already stopped. Meaning, between + // the time of the IsRunning() call above and now it stopped. + // Also, since the err return will be exec driver specific we can't + // look for any particular (common) error that would indicate + // that the process is already dead vs something else going wrong. + // So, instead we'll give it up to 2 more seconds to complete and if + // by that time the container is still running, then the error + // we got is probably valid and so we return it to the caller. + + if container.IsRunning() { + container.WaitStop(2 * time.Second) + if container.IsRunning() { + return err + } + } } // 2. Wait for the process to die, in last resort, try to kill the process directly