diff --git a/cmd/podman/containers/create.go b/cmd/podman/containers/create.go index ef58af06a3..2da313c68a 100644 --- a/cmd/podman/containers/create.go +++ b/cmd/podman/containers/create.go @@ -203,7 +203,7 @@ func replaceContainer(name string) error { Force: true, // force stop & removal Ignore: true, // ignore errors when a container doesn't exit } - return removeContainers([]string{name}, rmOptions, false) + return removeContainers([]string{name}, rmOptions, false, true) } func createOrUpdateFlags(cmd *cobra.Command, vals *entities.ContainerCreateOptions) error { diff --git a/cmd/podman/containers/rm.go b/cmd/podman/containers/rm.go index 705ac55082..a29233cf3c 100644 --- a/cmd/podman/containers/rm.go +++ b/cmd/podman/containers/rm.go @@ -133,14 +133,14 @@ func rm(cmd *cobra.Command, args []string) error { rmOptions.Depend = true } - return removeContainers(utils.RemoveSlash(args), rmOptions, true) + return removeContainers(utils.RemoveSlash(args), rmOptions, true, false) } // removeContainers will remove the specified containers (names or IDs). // Allows for sharing removal logic across commands. If setExit is set, // removeContainers will set the exit code according to the `podman-rm` man // page. -func removeContainers(namesOrIDs []string, rmOptions entities.RmOptions, setExit bool) error { +func removeContainers(namesOrIDs []string, rmOptions entities.RmOptions, setExit bool, quiet bool) error { var errs utils.OutputErrors responses, err := registry.ContainerEngine().ContainerRm(context.Background(), namesOrIDs, rmOptions) if err != nil { @@ -166,9 +166,13 @@ func removeContainers(namesOrIDs []string, rmOptions entities.RmOptions, setExit } errs = append(errs, r.Err) case r.RawInput != "": - fmt.Println(r.RawInput) + if !quiet { + fmt.Println(r.RawInput) + } default: - fmt.Println(r.Id) + if !quiet { + fmt.Println(r.Id) + } } } return errs.PrintErrors() diff --git a/test/e2e/run_test.go b/test/e2e/run_test.go index 0b65122c9c..423c2e44c4 100644 --- a/test/e2e/run_test.go +++ b/test/e2e/run_test.go @@ -1615,9 +1615,12 @@ VOLUME %s`, ALPINE, volPath, volPath) // Run and replace 5 times in a row the "same" container. ctrName := "testCtr" for i := 0; i < 5; i++ { - session := podmanTest.Podman([]string{"run", "--detach", "--replace", "--name", ctrName, ALPINE, "/bin/sh"}) + session := podmanTest.Podman([]string{"run", "--detach", "--replace", "--name", ctrName, ALPINE, "top"}) session.WaitWithDefaultTimeout() Expect(session).Should(ExitCleanly()) + + // make sure Podman prints only one ID + Expect(session.OutputToString()).To(HaveLen(64)) } })