diff --git a/libpod/container_api.go b/libpod/container_api.go index e179665d59..14d0b7e634 100644 --- a/libpod/container_api.go +++ b/libpod/container_api.go @@ -244,7 +244,12 @@ func (c *Container) Kill(signal uint) error { c.newContainerEvent(events.Kill) - return c.save() + // Make sure to wait for the container to exit in case of SIGKILL. + if signal == uint(unix.SIGKILL) { + return c.waitForConmonToExitAndSave() + } + + return nil } // Attach attaches to a container. diff --git a/libpod/container_internal.go b/libpod/container_internal.go index 7f8f467543..13feb2ffeb 100644 --- a/libpod/container_internal.go +++ b/libpod/container_internal.go @@ -1325,7 +1325,10 @@ func (c *Container) stop(timeout uint) error { c.newContainerEvent(events.Stop) c.state.StoppedByUser = true + return c.waitForConmonToExitAndSave() +} +func (c *Container) waitForConmonToExitAndSave() error { conmonAlive, err := c.ociRuntime.CheckConmonRunning(c) if err != nil { return err diff --git a/test/e2e/attach_test.go b/test/e2e/attach_test.go index b110f7c5b2..c2bc582087 100644 --- a/test/e2e/attach_test.go +++ b/test/e2e/attach_test.go @@ -82,6 +82,7 @@ var _ = Describe("Podman attach", func() { Expect(results.OutputToString()).To(ContainSubstring("test")) Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1)) }) + It("podman attach to the latest container", func() { session := podmanTest.Podman([]string{"run", "-d", "--name", "test1", ALPINE, "/bin/sh", "-c", "while true; do echo test1; sleep 1; done"}) session.WaitWithDefaultTimeout()