mirror of
https://github.com/containers/podman.git
synced 2025-12-02 19:17:00 +08:00
podman: run --replace prints only the new container id
print only the new container ID when using --replace instead of the terminated container ID if it was stopped. Closes: https://github.com/containers/podman/issues/20185 Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
@@ -203,7 +203,7 @@ func replaceContainer(name string) error {
|
|||||||
Force: true, // force stop & removal
|
Force: true, // force stop & removal
|
||||||
Ignore: true, // ignore errors when a container doesn't exit
|
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 {
|
func createOrUpdateFlags(cmd *cobra.Command, vals *entities.ContainerCreateOptions) error {
|
||||||
|
|||||||
@@ -133,14 +133,14 @@ func rm(cmd *cobra.Command, args []string) error {
|
|||||||
rmOptions.Depend = true
|
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).
|
// removeContainers will remove the specified containers (names or IDs).
|
||||||
// Allows for sharing removal logic across commands. If setExit is set,
|
// Allows for sharing removal logic across commands. If setExit is set,
|
||||||
// removeContainers will set the exit code according to the `podman-rm` man
|
// removeContainers will set the exit code according to the `podman-rm` man
|
||||||
// page.
|
// 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
|
var errs utils.OutputErrors
|
||||||
responses, err := registry.ContainerEngine().ContainerRm(context.Background(), namesOrIDs, rmOptions)
|
responses, err := registry.ContainerEngine().ContainerRm(context.Background(), namesOrIDs, rmOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -166,9 +166,13 @@ func removeContainers(namesOrIDs []string, rmOptions entities.RmOptions, setExit
|
|||||||
}
|
}
|
||||||
errs = append(errs, r.Err)
|
errs = append(errs, r.Err)
|
||||||
case r.RawInput != "":
|
case r.RawInput != "":
|
||||||
fmt.Println(r.RawInput)
|
if !quiet {
|
||||||
|
fmt.Println(r.RawInput)
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
fmt.Println(r.Id)
|
if !quiet {
|
||||||
|
fmt.Println(r.Id)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return errs.PrintErrors()
|
return errs.PrintErrors()
|
||||||
|
|||||||
@@ -1615,9 +1615,12 @@ VOLUME %s`, ALPINE, volPath, volPath)
|
|||||||
// Run and replace 5 times in a row the "same" container.
|
// Run and replace 5 times in a row the "same" container.
|
||||||
ctrName := "testCtr"
|
ctrName := "testCtr"
|
||||||
for i := 0; i < 5; i++ {
|
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()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session).Should(ExitCleanly())
|
Expect(session).Should(ExitCleanly())
|
||||||
|
|
||||||
|
// make sure Podman prints only one ID
|
||||||
|
Expect(session.OutputToString()).To(HaveLen(64))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user