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?
The commit operation will not include any data contained in volumes mounted inside the container.
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.
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.
docker commit
command.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
Once inside the container, tar the folder where the volume is mounted.
Copy the volume tar from the dummy container to your host using
docker cp backup: volume.tar
Now you have multiple options:
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
Or untar the volume backup and mount it as a bind mount on the new container created from the container-commit image
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With