Skip to content

Commit

Permalink
Do not remove volumes when --rm removes a container
Browse files Browse the repository at this point in the history
This duplicates Docker behavior for the `--rm` flag.

Fixes containers#3071

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
  • Loading branch information
mheon committed May 6, 2019
1 parent a9fc570 commit 5c6ff90
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/podman-create.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ Automatically remove the container when it exits. The default is *false*.

Note that the container will not be removed when it could not be created or
started successfully. This allows the user to inspect the container after
failure. The `--rm` flag is incompatible with the `-d` flag.
failure.

**--rootfs**

Expand Down
2 changes: 1 addition & 1 deletion docs/podman-run.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ Automatically remove the container when it exits. The default is *false*.

Note that the container will not be removed when it could not be created or
started successfully. This allows the user to inspect the container after
failure. The `--rm` flag is incompatible with the `-d` flag.
failure.

**--rootfs**

Expand Down
7 changes: 5 additions & 2 deletions pkg/adapter/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,9 @@ func (r *LocalRuntime) Run(ctx context.Context, c *cliconfig.RunValues, exitCode
}

if c.IsSet("rm") {
r.Runtime.RemoveContainer(ctx, ctr, false, true)
if err := r.Runtime.RemoveContainer(ctx, ctr, false, false); err != nil {
logrus.Errorf("Error removing container %s: %v", ctr.ID(), err)
}
}

return exitCode, nil
Expand Down Expand Up @@ -965,8 +967,9 @@ func (r *LocalRuntime) CleanupContainers(ctx context.Context, cli *cliconfig.Cle
return ok, failures, nil
}

// Only used when cleaning up containers
func removeContainer(ctx context.Context, ctr *libpod.Container, runtime *LocalRuntime) error {
if err := runtime.RemoveContainer(ctx, ctr, false, true); err != nil {
if err := runtime.RemoveContainer(ctx, ctr, false, false); err != nil {
return errors.Wrapf(err, "failed to cleanup and remove container %v", ctr.ID())
}
return nil
Expand Down

0 comments on commit 5c6ff90

Please sign in to comment.