How to remove configure volumes in docker images

前端 未结 3 511
盖世英雄少女心
盖世英雄少女心 2020-12-21 00:12

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 insp

相关标签:
3条回答
  • 2020-12-21 00:18

    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
    
    0 讨论(0)
  • 2020-12-21 00:22

    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.

    0 讨论(0)
  • 2020-12-21 00:27

    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
    0 讨论(0)
提交回复
热议问题