How to remove configure volumes in docker images

2019-02-25 18:42发布

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?

3条回答
爷的心禁止访问
2楼-- · 2019-02-25 18:50

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
查看更多
Rolldiameter
3楼-- · 2019-02-25 19:01

An easy way to remove volumes is to export and then import the container image:

  • docker run --name my-container -it [image] /bin/bash
  • docker export my-container > tarball
  • docker import tarball
查看更多
Melony?
4楼-- · 2019-02-25 19:09

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.

查看更多
登录 后发表回答