From ee198d09c43b27b26153a34ca83d9d7f7641593b Mon Sep 17 00:00:00 2001 From: Brian Goff Date: Thu, 21 Jan 2016 21:57:53 -0500 Subject: [PATCH] On container rm, don't remove named mountpoints This makes it so when calling `docker run --rm`, or `docker rm -v`, only volumes specified without a name, e.g. `docker run -v /foo` instead of `docker run -v awesome:/foo` are removed. Note that all volumes are named, some are named by the user, some get a generated name. This is specifically about how the volume was specified on `run`, assuming that if the user specified it with a name they expect it to persist after the container is cleaned up. Signed-off-by: Brian Goff Upstream-commit: 8de6a3fc71654e08d7a0e65651302dcba5d1b9e1 Component: cli --- components/cli/docs/reference/commandline/rm.md | 14 ++++++++++++++ components/cli/docs/reference/run.md | 6 +++++- components/cli/man/docker-rm.1.md | 16 ++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/components/cli/docs/reference/commandline/rm.md b/components/cli/docs/reference/commandline/rm.md index 3664f98ccd..514b92c27e 100644 --- a/components/cli/docs/reference/commandline/rm.md +++ b/components/cli/docs/reference/commandline/rm.md @@ -45,3 +45,17 @@ This command will delete all stopped containers. The command `docker ps -a -q` will return all existing container IDs and pass them to the `rm` command which will delete them. Any running containers will not be deleted. + + $ docker rm -v redis + redis + +This command will remove the container and any volumes associated with it. +Note that if a volume was specified with a name, it will not be removed. + + $ docker create -v awesome:/foo -v /bar --name hello redis + hello + $ docker rm -v hello + +In this example, the volume for `/foo` will remain intact, but the volume for +`/bar` will be removed. The same behavior holds for volumes inherited with +`--volumes-from`. diff --git a/components/cli/docs/reference/run.md b/components/cli/docs/reference/run.md index 1e79953139..537e3aa085 100644 --- a/components/cli/docs/reference/run.md +++ b/components/cli/docs/reference/run.md @@ -590,7 +590,11 @@ the container exits**, you can add the `--rm` flag: > **Note**: When you set the `--rm` flag, Docker also removes the volumes associated with the container when the container is removed. This is similar -to running `docker rm -v my-container`. +to running `docker rm -v my-container`. Only volumes that are specified without a +name are removed. For example, with +`docker run --rm -v /foo -v awesome:/bar busybox top`, the volume for `/foo` will be removed, +but the volume for `/bar` will not. Volumes inheritted via `--volumes-from` will be removed +with the same logic -- if the original volume was specified with a name it will **not** be removed. ## Security configuration --security-opt="label:user:USER" : Set the label user for the container diff --git a/components/cli/man/docker-rm.1.md b/components/cli/man/docker-rm.1.md index d99c1d836b..9ae3142a6c 100644 --- a/components/cli/man/docker-rm.1.md +++ b/components/cli/man/docker-rm.1.md @@ -48,6 +48,22 @@ command. The use that name as follows: docker rm hopeful_morse +## Removing a container and all associated volumes + + $ docker rm -v redis + redis + +This command will remove the container and any volumes associated with it. +Note that if a volume was specified with a name, it will not be removed. + + $ docker create -v awesome:/foo -v /bar --name hello redis + hello + $ docker rm -v hello + +In this example, the volume for `/foo` will remain in tact, but the volume for +`/bar` will be removed. The same behavior holds for volumes inherited with +`--volumes-from`. + # HISTORY April 2014, Originally compiled by William Henry (whenry at redhat dot com) based on docker.com source material and internal work.