Skip to content

skip the volumes mounted when deleting the volumes of container.#2488

Merged
crosbymichael merged 2 commits intomoby:masterfrom
viirya:fix_container_volumes_delete
Nov 22, 2013
Merged

skip the volumes mounted when deleting the volumes of container.#2488
crosbymichael merged 2 commits intomoby:masterfrom
viirya:fix_container_volumes_delete

Conversation

@viirya
Copy link
Copy Markdown
Contributor

@viirya viirya commented Oct 31, 2013

The volumes created by mounting with '-v' when running container are not correctly processed. Run 'docker rm' for such containers casts errors.

This PR skips those volumes when deleting containers to fix this problem.

@vieux
Copy link
Copy Markdown
Contributor

vieux commented Nov 1, 2013

Hi,

The best would be to not delete anything and to return an error to the client.
Something like, "xxx volumes are still in use, can't remove them"

Thanks

@viirya
Copy link
Copy Markdown
Contributor Author

viirya commented Nov 1, 2013

Let me explain clearer.

Suppose we launch a container by:
sudo docker run -lxc-conf=lxc.aa_profile=unconfined -privileged -v pwd:/go/src/github.com/dotcloud/docker docker

And pwd is '/home/user/docker' here.

The behavior of original codes would try to trim the right of volumeId:

   // volumeId is '/home/user/docker' at first

   volumeId = strings.TrimRight(volumeId, "/layer")  // volumeId now becomes '/home/user/dock'
   volumeId = filepath.Base(volumeId)                        // volumeId now becomes 'dock'

Then the later code in same function:
err := srv.runtime.volumes.Delete(volumeId); // error happens because the volume 'dock' doesn't exist

Because of returing the error, the other volumes of the container are not deleted. But the container is deleted already. So those volumes would be left in disk.

Since the volume is mounted from external of the container (i.e. host), it would be best not to delete it (otherwise '/home/user/docker' would be removed). So this PR tries to skip those mounted volumes.

The usage of TrimRight in original codes has problem. It will remove the 'er' from 'docker', for example. But I do not think that is what we want here. So this PR uses TrimSuffix instead. If there is no the suffix '/layer' in volumeId, we think it is a mounted volume and skip it in later deleting.

@creack
Copy link
Copy Markdown
Contributor

creack commented Nov 6, 2013

ping @vieux

Comment thread server.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This most likely needs to be go fmt'd

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. thanks.

@vieux
Copy link
Copy Markdown
Contributor

vieux commented Nov 12, 2013

Hi @viirya , sorry for the late reply.

I understand your point.
The only thing I'm not fond of is that you use /layer to detect if the volume in mounted on the host or not.

docker run -i -t -v /tmp/test/layer:/tmp/test ubuntu bash
docker rm -v `docker ps -l -q`

The best practice would be to use look as the Binds key in the hostConfig.

Could you update your PR ?

Thanks

@viirya
Copy link
Copy Markdown
Contributor Author

viirya commented Nov 13, 2013

Hi @vieux, modified codes use Binds key to detect mounted volumes. Thanks.

@vieux
Copy link
Copy Markdown
Contributor

vieux commented Nov 13, 2013

LGTM, ping @shykes @crosbymichael

@crosbymichael
Copy link
Copy Markdown
Contributor

LGTM

crosbymichael added a commit that referenced this pull request Nov 22, 2013
Skip the volumes mounted when deleting the volumes of container.
@crosbymichael crosbymichael merged commit 70f1bd3 into moby:master Nov 22, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants