简体   繁体   中英

How to export/save an entire Docker container/image

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.

  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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM