Merge pull request #19482 from rhatdan/rmi

Make podman run --rmi automatically set --rm
This commit is contained in:
OpenShift Merge Robot 2023-08-03 10:55:00 +02:00 committed by GitHub
commit b8c9ad8982
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 3 deletions

View File

@ -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")

View File

@ -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

View File

@ -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.