mirror of
https://github.com/containers/podman.git
synced 2025-06-24 11:28:24 +08:00
Make podman run --rmi automatically set --rm
Forcing users to set --rm when setting --rmi is just bad UI. If I want the image to be removed, it implies that I want the container removed that I am creating. Fixes: https://github.com/containers/podman/issues/15640 Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package containers
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
@ -63,7 +64,7 @@ func runFlags(cmd *cobra.Command) {
|
||||
|
||||
flags.SetNormalizeFunc(utils.AliasFlags)
|
||||
flags.BoolVar(&runOpts.SigProxy, "sig-proxy", true, "Proxy received signals to the process")
|
||||
flags.BoolVar(&runRmi, "rmi", false, "Remove container image unless used by other containers")
|
||||
flags.BoolVar(&runRmi, "rmi", false, "Remove image unless used by other containers, implies --rm=true")
|
||||
|
||||
preserveFdsFlagName := "preserve-fds"
|
||||
flags.UintVar(&runOpts.PreserveFDs, "preserve-fds", 0, "Pass a number of additional file descriptors into the container")
|
||||
@ -110,6 +111,12 @@ func run(cmd *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if runRmi {
|
||||
if cmd.Flags().Changed("rm") && !cliVals.Rm {
|
||||
return errors.New("the --rmi option does not work without --rm=true")
|
||||
}
|
||||
cliVals.Rm = true
|
||||
}
|
||||
// TODO: Breaking change should be made fatal in next major Release
|
||||
if cliVals.TTY && cliVals.Interactive && !term.IsTerminal(int(os.Stdin.Fd())) {
|
||||
logrus.Warnf("The input device is not a TTY. The --tty and --interactive flags might not work properly")
|
||||
|
@ -347,7 +347,7 @@ the container when it exits. The default is **false**.
|
||||
#### **--rmi**
|
||||
|
||||
After exit of the container, remove the image unless another
|
||||
container is using it. The default is *false*.
|
||||
container is using it. Implies --rm=true on the new container. The default is *false*.
|
||||
|
||||
@@option rootfs
|
||||
|
||||
|
@ -182,12 +182,16 @@ echo $rand | 0 | $rand
|
||||
|
||||
# Now try running with --rmi : it should succeed, but not remove the image
|
||||
run_podman run --rmi --rm $NONLOCAL_IMAGE /bin/true
|
||||
is "$output" ".*image is in use by a container" "--rmi should warn that the image was not removed"
|
||||
run_podman image exists $NONLOCAL_IMAGE
|
||||
|
||||
# Remove the stray container, and run one more time with --rmi.
|
||||
run_podman rm /keepme
|
||||
run_podman run --rmi --rm $NONLOCAL_IMAGE /bin/true
|
||||
run_podman run --rmi $NONLOCAL_IMAGE /bin/true
|
||||
run_podman 1 image exists $NONLOCAL_IMAGE
|
||||
|
||||
run_podman 125 run --rmi --rm=false $NONLOCAL_IMAGE /bin/true
|
||||
is "$output" "Error: the --rmi option does not work without --rm=true" "--rmi should refuse to remove images when --rm=false set by user"
|
||||
}
|
||||
|
||||
# 'run --conmon-pidfile --cid-file' makes sure we don't regress on these flags.
|
||||
|
Reference in New Issue
Block a user