Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove configure volumes in docker images

I use docker run -it -v /xx1 -v /xx2 [image] /bin/bash to create a container.

Then commit to image and push to docker hub.

use docker inspect [image]

The Volumes detail is

"Volumes": {
            "/xx1": {},
            "/xx2": {}
        },

Now I want to remove volume /xx1 in this image.

What should I do?

like image 396
Jiacheng-z Avatar asked Sep 20 '16 08:09

Jiacheng-z


2 Answers

I don't think this is possible with the Docker tools right now. You can't remove a volume from a running container, or if you were to use your image as the base in a new Dockerfile you can't remove the inherited volumes.

Possibly you could use Jérôme Petazzoni's nsenter tool to manually remove the mount inside the container and then commit. You can use that approach to attach a volume to a running container, but there's some fairly low-level hacking needed to do it.

like image 58
Elton Stoneman Avatar answered Oct 19 '22 18:10

Elton Stoneman


There is a workaround in that you can docker save image1 -o archive.tar, editing the metadata json file, and docker import -i archive.tar. That way the history and all the other metadata is preserved.

To help with save/unpack/edit/load I have created a little script, have a look at docker-copyedit. Specifically for your question you would execute

./docker-copyedit.py from [image] into [image2] remove volume /xx1
like image 3
Guido U. Draheim Avatar answered Oct 19 '22 17:10

Guido U. Draheim