1

I installed a MySQL Docker image onto my system, configured and started a container off of it and imported a 2+ GB (bz2 compressed size) database into it. I would like to pack the entire container and transfer it onto another system.

If I stop the running container and perform an export, it yields only a 118MB tar.bz file.

If I commit my container into an image and save it, that also yields only a 118MB tar.bz file.

What's the way to export/save the entirety of the container including the MySQL data? The MySQL image is 383.4MB and my modified image is also the same.


I've found some trail: How can I backup a Docker-container with its data-volumes?


Addition: currently I'm using an Ubuntu Linux flavor.

Csaba Toth
  • 10,021
  • 5
  • 75
  • 121
  • 1
    Are you using the standard MySQL image? If so, did you happen to map the volumes to anything outside of the container? – Roman Nov 08 '16 at 01:28
  • I started from the standard MySQL package and I changed only one setting in the mysqld.cnf so I can import my saved DB. I haven't done any configuration about volume mapping per se, Hy L's answer looks good, I'll check it soon. – Csaba Toth Nov 08 '16 at 15:51
  • I would also take a look at the [cp](https://docs.docker.com/engine/reference/commandline/cp/) command. I haven't tried to see if it will copy data out of hosts or not – Roman Nov 08 '16 at 16:05
  • @ROMANARMY I used `docker cp` to modify the MySQL config in the container. @Hy L described well that the meat is outside of the container in `/var/lib/docker/volumes/...` – Csaba Toth Nov 09 '16 at 20:54
  • Just realized my typo, I meant copy data out of volumes. You could probably use `docker exec` to open a shell into your container and modify any config you'd like that way. – Roman Nov 10 '16 at 00:09

1 Answers1

1
  1. Find where the data is stored that matches your container (as a sudo user, you can access /var/lib/docker/volumes/{container_id}, /var/lib/docker/vfs/dir/{container_id})

  2. Move the data along with your container to the place you want to run.

  3. Use volume mapping when you start the container, so you can have more control of it.

Below are the knowledge could be helpful for you:

A Docker volume permits data to be stored in a container outside of the boot volume (but within the root file system).

A container can be created with one or more volumes by providing a share name passed to the "-v" switch parameter (for example, /dockerdata). This has the effect of creating an entity within the Docker configuration folder (/var/lib/docker) that represents the contents of the volume.

Configuration data on volumes is stored in the /var/lib/docker/volumes folder, with each sub-directory representing a volume name based on a UUID. The data itself is stored in the /var/lib/docker/vfs/dir folder (again based on UUID name).

The data in any volume can be freely browsed and edited by the host operating system, and standard Unix permissions apply.

The use of volumes has advantages and disadvantages. As the data is stored in a standard file system, it can be backed up, copied or moved in and out by the operating system.

The disadvantage here is that the volume name is in UUID format and that makes it tricky to associate with a container name. Docker makes things easier by providing the "docker cp" command that allows files and folders to be copied from a host directory to a container directory path by specifying the container name.

A Docker volume can also be associated with a host directory. This is again specified on the "-v" switch, using a format that separates the host and container paths with a colon, as follows: "-v /host:/container". This method allows persistent data on the host to be accessed by a container.

It would therefore be possible to provide access to external shared storage on an NFS share or LUN by using the volume option to access a host share created on the external storage. This method could also be used to back up the data accessed by containers.

Hy L
  • 522
  • 5
  • 11