21

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?

xetra11
  • 7,671
  • 14
  • 84
  • 159

1 Answers1

27

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:<path-to-tar> 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
  1. Or untar the volume backup and mount it as a bind mount on the new container created from the container-commit image
TmTron
  • 17,012
  • 10
  • 94
  • 142
yamenk
  • 46,736
  • 10
  • 93
  • 87
  • 4
    Ah okay I get it. I need to get into my container, archive the files I want to "port" and then COPY these into the new image. – xetra11 Sep 21 '17 at 20:26
  • It would be a great feature for taking snapshots of running containers before doing tasks such as upgrades where data migration might exist. – Dean Meehan Sep 14 '22 at 11:38