Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Commit content of mounted volumes as well

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 mounted volumes - so I have to unmount them.

Is there a way to let docker mount volumes and commit changes of the directories?

I read about the readonly option for volume bindings. Might that help?

like image 232
xetra11 Avatar asked Sep 21 '17 16:09

xetra11


People also ask

Does Docker commit include volumes?

The commit operation will not include any data contained in volumes mounted inside the container.

What is mounting volumes in Docker?

Docker volumes are file systems mounted on Docker containers to preserve data generated by the running container. The volumes are stored on the host, independent of the container life cycle. This allows users to back up data and share file systems between containers easily.


1 Answers

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

like image 59
yamenk Avatar answered Oct 03 '22 18:10

yamenk