summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-03-04 10:58:10 -0500
committerGitHub <noreply@github.com>2020-03-04 10:58:10 -0500
commit90eef95cb1591f20f5716225cf9b2c8c415fc3fc (patch)
tree9f19d9affffb9c57b5888e2fb3d12b9c642d4a73 /cmd
parenta8bc423e2989ceff1ee2ca79d6c1bd8314901e11 (diff)
parent11e5c53d1191f7a324f212aa2ca2ec2aad1b4676 (diff)
downloadpodman-90eef95cb1591f20f5716225cf9b2c8c415fc3fc.tar.gz
podman-90eef95cb1591f20f5716225cf9b2c8c415fc3fc.tar.bz2
podman-90eef95cb1591f20f5716225cf9b2c8c415fc3fc.zip
Merge pull request #4772 from boaz0/closes_4628
Add the rmi flag to podman-run to delete container image
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/cleanup.go1
-rw-r--r--cmd/podman/cliconfig/config.go7
-rw-r--r--cmd/podman/run.go10
3 files changed, 15 insertions, 3 deletions
diff --git a/cmd/podman/cleanup.go b/cmd/podman/cleanup.go
index a8bc0c116..80a19b000 100644
--- a/cmd/podman/cleanup.go
+++ b/cmd/podman/cleanup.go
@@ -44,6 +44,7 @@ func init() {
flags.BoolVarP(&cleanupCommand.All, "all", "a", false, "Cleans up all containers")
flags.BoolVarP(&cleanupCommand.Latest, "latest", "l", false, "Act on the latest container podman is aware of")
flags.BoolVar(&cleanupCommand.Remove, "rm", false, "After cleanup, remove the container entirely")
+ flags.BoolVar(&cleanupCommand.RemoveImage, "rmi", false, "After cleanup, remove the image entirely")
markFlagHiddenForRemoteClient("latest", flags)
}
diff --git a/cmd/podman/cliconfig/config.go b/cmd/podman/cliconfig/config.go
index ccc30c603..79917946a 100644
--- a/cmd/podman/cliconfig/config.go
+++ b/cmd/podman/cliconfig/config.go
@@ -658,9 +658,10 @@ type VolumeRmValues struct {
type CleanupValues struct {
PodmanCommand
- All bool
- Latest bool
- Remove bool
+ All bool
+ Latest bool
+ Remove bool
+ RemoveImage bool
}
type SystemPruneValues struct {
diff --git a/cmd/podman/run.go b/cmd/podman/run.go
index 219f057c3..27247c5b5 100644
--- a/cmd/podman/run.go
+++ b/cmd/podman/run.go
@@ -7,6 +7,7 @@ import (
"github.com/containers/libpod/pkg/adapter"
"github.com/opentracing/opentracing-go"
"github.com/pkg/errors"
+ "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@@ -38,6 +39,7 @@ func init() {
flags.SetInterspersed(false)
flags.SetNormalizeFunc(aliasFlags)
flags.Bool("sig-proxy", true, "Proxy received signals to the process")
+ flags.Bool("rmi", false, "Remove container image unless used by other containers")
flags.AddFlagSet(getNetFlags())
getCreateFlags(&runCommand.PodmanCommand)
markFlagHiddenForRemoteClient("authfile", flags)
@@ -64,5 +66,13 @@ func runCmd(c *cliconfig.RunValues) error {
defer runtime.DeferredShutdown(false)
exitCode, err = runtime.Run(getContext(), c, exitCode)
+ if c.Bool("rmi") {
+ imageName := c.InputArgs[0]
+ if newImage, newImageErr := runtime.NewImageFromLocal(imageName); newImageErr != nil {
+ logrus.Errorf("%s", errors.Wrapf(newImageErr, "failed creating image object"))
+ } else if _, errImage := runtime.RemoveImage(getContext(), newImage, false); errImage != nil {
+ logrus.Errorf("%s", errors.Wrapf(errImage, "failed removing image"))
+ }
+ }
return err
}