Commit content of mounted volumes as well

前端 未结 1 417
一整个雨季
一整个雨季 2020-12-13 22:33

I have a jenkins container running and would like to have it\'s configuration isolated in a container commit. Only problem is that there docker won\'t commit changes of moun

相关标签:
1条回答
  • 2020-12-13 23:04

    Unfortunately, this feature is not available. It has been proposed many times but not accepted by the developers. The main reason is portability; volumes are not supposed to be part of the image, and are stored outside the image.

    You can still however achieve the same thing indirectly.

    1. Commit you container using the docker commit command.
    2. Start a new dummy container that uses the volume from the container that you are trying to backup.

      docker run -volumes-from <container-name> --name backup -it ubuntu bash

    3. Once inside the container, tar the folder where the volume is mounted.

    4. Copy the volume tar from the dummy container to your host using

      docker cp backup: volume.tar

    Now you have multiple options:

    1. Create a new image using Dockerfile:

      FROM commited-container-image COPY volume.tar . RUN tar -xf volume.tar -C path-to-volume-mount-point &&\ rm -f volume.tar

    2. Or untar the volume backup and mount it as a bind mount on the new container created from the container-commit image

    0 讨论(0)
提交回复
热议问题