diff options
author | Boaz Shuster <boaz.shuster.github@gmail.com> | 2020-01-01 09:53:25 +0200 |
---|---|---|
committer | Boaz Shuster <boaz.shuster.github@gmail.com> | 2020-03-03 14:27:11 +0200 |
commit | 11e5c53d1191f7a324f212aa2ca2ec2aad1b4676 (patch) | |
tree | d90b96daccd6e8459adac7a5553766c858bc3bde /pkg | |
parent | 1641ee61802ad5e13a9ddf0a20099fe31f73768d (diff) | |
download | podman-11e5c53d1191f7a324f212aa2ca2ec2aad1b4676.tar.gz podman-11e5c53d1191f7a324f212aa2ca2ec2aad1b4676.tar.bz2 podman-11e5c53d1191f7a324f212aa2ca2ec2aad1b4676.zip |
Add the rmi flag to podman-run to delete container image
The --rmi flag will delete the container image after its execution
unless that image is already been used by another container(s).
This is useful when one wants to execute a container once and remove
any resources attached to it.
Signed-off-by: Boaz Shuster <boaz.shuster.github@gmail.com>
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/adapter/containers.go | 19 | ||||
-rw-r--r-- | pkg/spec/createconfig.go | 5 |
2 files changed, 24 insertions, 0 deletions
diff --git a/pkg/adapter/containers.go b/pkg/adapter/containers.go index 08e19edb8..ab664e1c3 100644 --- a/pkg/adapter/containers.go +++ b/pkg/adapter/containers.go @@ -1101,6 +1101,15 @@ func (r *LocalRuntime) CleanupContainers(ctx context.Context, cli *cliconfig.Cle } else { failures[ctr.ID()] = err } + + if cli.RemoveImage { + _, imageName := ctr.Image() + if err := removeContainerImage(ctx, ctr, r); err != nil { + failures[imageName] = err + } else { + ok = append(ok, imageName) + } + } } return ok, failures, nil } @@ -1120,6 +1129,16 @@ func cleanupContainer(ctx context.Context, ctr *libpod.Container, runtime *Local return nil } +func removeContainerImage(ctx context.Context, ctr *libpod.Container, runtime *LocalRuntime) error { + _, imageName := ctr.Image() + ctrImage, err := runtime.NewImageFromLocal(imageName) + if err != nil { + return err + } + _, err = runtime.RemoveImage(ctx, ctrImage, false) + return err +} + // Port displays port information about existing containers func (r *LocalRuntime) Port(c *cliconfig.PortValues) ([]*Container, error) { var ( diff --git a/pkg/spec/createconfig.go b/pkg/spec/createconfig.go index 02678a687..eb2cac8b8 100644 --- a/pkg/spec/createconfig.go +++ b/pkg/spec/createconfig.go @@ -156,6 +156,7 @@ type CreateConfig struct { Resources CreateResourceConfig RestartPolicy string Rm bool //rm + Rmi bool //rmi StopSignal syscall.Signal // stop-signal StopTimeout uint // stop-timeout Systemd bool @@ -233,6 +234,10 @@ func (c *CreateConfig) createExitCommand(runtime *libpod.Runtime) ([]string, err command = append(command, "--rm") } + if c.Rmi { + command = append(command, "--rmi") + } + return command, nil } |