1

The postgres image, for example, has a volume baked in at /var/lib/postgresl/data, but it isn't bound to a particular host path. I'm wondering if the database work done in this container is wholly encapsulated by committing the container to an image, or if I need to separately pass along the contents of the unbound volume.

Example in commands

Create container vtest based on postgres image:

$ docker run -d --name vtest postgres

The container has a volume at /var/lib/postgresql/data that is not bound to a host path:

$ docker inspect -f '{{ .Volumes }}' vtest
map[/var/lib/postgresql/data:/var/lib/docker/vfs/dir/bc39da05ff1cd044d7a17bba61381e854a948fb70cf39f897247f5ada66ad906]
$ sudo docker inspect -f '{{ .HostConfig.Binds }}' vtest
<no value>

Create a database and add some records in the vtest container. Then, commit the changes to an image to be able to share with others:

$ docker commit -p vtest postgres:vtest

Will the changes made in the vtest container's /var/lib/postgresql/data persist in this new postgres:vtest image?

Community
  • 1
  • 1
CivFan
  • 13,560
  • 9
  • 41
  • 58

1 Answers1

3

The volumes mounted in the container are not committed to the image, not matter it is mounted to a particular folder of your host or it's mounted to a folder in /var/lib/docker. In fact, as you show in your message, the volume is mounted to /var/lib/docker/vfs/dir/bc39da05ff1cd044d7a17bba61381e854a948fb70cf39f897247f5ada66ad906 in host machine. You can browse that folder as root user.

If you want to save the data in a volume you would need to use other approach different to committing. One of the more used ones is using data containers (which will create also a folder in /var/lib/container/... with your data), and then saving that volume using a new container an a packing tool like tar. Check Docker documentation related to this topic for further details.

Javier Cortejoso
  • 8,851
  • 3
  • 26
  • 27
  • Seems odd that you have to go outside docker to share the actual volume data, so I figured I was missing something. I guess not! Thanks for the `tar` workflow tip. – CivFan May 15 '15 at 18:41