Docker Tutorial: Docker Image Export and migration

Source: Internet
Author: User
Tags rsync docker ps docker run

http://blog.csdn.net/pipisorry/article/details/51330126

Docker Directory AnalysisinstallationDocker, the default installation location is/var/lib/docker. $sudo ls/var/lib/docker/
Aufs Containers Graph Init linkgraph.db repositories-aufsTMP Trust volumes

REPOSITORIES-AUFS: A JSON file that records the image name and the corresponding ID
Graph: The metadata for the downloaded image is saved, including JSON and Layersize, where the JSON file records the corresponding image ID, dependencies, creation time, configuration information, and so on. Layersize is the size of the corresponding layer. Entering the graph file will find that the next bread contains multiple folders and enters one of the folders
ROOT:/VAR/LIB/DOCKER/GRAPH#CD 09694f91574ea3fca8558306c55abbbd47e01b8cb9ae782c66b9682a95c7f71e/
Root:/var/lib/docker/graph/09694f91574ea3fca8558306c55abbbd47e01b8cb9ae782c66b9682a95c7f71e#ls
JSON layersize
You can see the JSON and layersize files.
The JSON file content Layersize may display as 0, this layer is 0, does not mean that the mirror size is 0. Graph storage image, is tiered storage, the graph directory of the extra folder is actually a layer. These layers are associated with a layer named after our mirror name, and the relationship is recorded in a JSON file. From this JSON file, you can see the parent image or the previous layer of the image is ..., the graph directory is also stored in this layer of information, and then look down, you can see the hierarchical relationship. In graph This directory does not find the location of the image we want to find. The graph directory is just some image-related information data. The image should contain a Linux-like file system.
Containers: The following is a container-related information, each running a container, under this directory to generate a container ID corresponding to the sub-directory.
Init: The information about Docker Init is saved.
TMP: is an empty directory, the specific role of what is unclear.
Volumes: Related to Docker data coupons.
Aufs Directory: MNT is the mount directory of the Aufs, diff is the actual data source, which is where our image is actually stored, including the read-only and read-write layers, all of which are eventually attached to the directory where the MMT resides. Layers for each layer depends on the description file.
There are 6 files or subdirectories under diff, mnt, layers, but from the graph directory our image should be 4 layers, why do we have 2 more? A closer look at a file or subdirectory will reveal that the name is identical to the container ID and that there is an init. In fact, before the container started, mnt and layers are empty directories, diff below also only the graph directory we see the mirror layer corresponding to the 4 directory. When Docker launches a container using image, it creates a new file and subdirectory for the container ID under Aufs, and creates a new read-write layer on the mirrored, readable level. As for the Id-init file or subdirectory records are information related to the environment in the container, regardless of the image.
Now that we know that the image is actually stored in the diff directory, let's look at the contents of each subdirectory in the diff directory. Viewed in the hierarchical relationship of the mirror. Eventually we see the same filesystem as Linux. has indicated that the image is actually stored in the diff directory.
In summary, the Docker image is ultimately stored in/var/lib/docker/aufs/diff, and there is a record of what is being done in graph. When the container starts, the readable layer image under diff and the new read-write layer "container ID" will be mounted to subdirectories under the container ID named in the MMT directory. [Docker imagewhere to store and in what form] Phi Phi Blog


Docker image Import ExportExport container Docker export container snapshot to local file
$ sudo docker ps-a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7691a814370e ubuntu:14.04 "/bin/bash" hours ago Exited (0) hours ago Test
$ sudo docker export 7691a814370e > Ubuntu.tar
Import container snapshot Docker Import from container snapshot file to mirror
$ Cat Ubuntu.tar | sudo docker import-test/ubuntu:v1.0
$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
Test/ubuntu v1.0 9d37a6082e97 about a minute ago 171.3 MB
Importing $sudo docker import Http://example.com/exampleimage.tgz by specifying a URL or a directory Example/imagerepo

Note: Users can either use Docker load to import a mirrored storage file to a local mirror library, or you can use Docker import to import a container snapshot to a local mirror library. The difference between the two is that the container snapshot file discards all history and metadata information (that is, only the snapshot state of the container at that time), while the mirrored storage file will hold the full record and be larger in size. In addition, metadata information such as labels can be re-specified when importing from a container snapshot file.
Phi Blog


Docker Image MigrationThe following $docker_dir represent/data/docker
Note: If you migrate to a disk under Windows such as/media/pika/files/mine/env/docker, the problem occurs:
sudo service docker restart
Stop:unknown Job:docker

Start:unknown Job:docker

[Starting Docker as Daemon on Ubuntu]

You can run it under #, but Docker run doesn't work, it's going to be a problem!

FIX: Re-install Docker

[Docker concept and installation :D Ocker unloading and reloading]

[ubuntu14.04 Docker container cannot be managed by service, solution]

So you don't have to move around if you don't have to!


The image of Docker and some data are in the/var/lib/docker directory, it occupies the Linux system partition, that is, the following/dev/sda2, when there are multiple mirrors, the space may be insufficient, we can mount the Docker data to the data disk, such as $ The Docker_dir directory.

$DF-LHT
Filesystem Type Size used Avail use% mounted on
Udev Devtmpfs 3.9G 4.0K 3.9G 1%/dev
Tmpfs tmpfs 781M 1.3M 780M 1%/run
/dev/sda2 ext4 148G 14G 127G 10%/
None Tmpfs 4.0K 0 4.0K 0%/sys/fs/cgroup
None Tmpfs 5.0M 0 5.0M 0%/run/lock
None Tmpfs 3.9G 36M 3.8G 1%/RUN/SHM
None Tmpfs 100M 72K 100M 1%/run/user
/dev/sda6 fuseblk 110G 99G 11G 91%/media/pika/files
/dev/sda5 fuseblk 98G 78G 20G 80%/media/pika/softwares

1 Stop Docker #service Docker stop

2 Creating a directory to mount in the data partition #mkdir-p $DOCKER _dir

3 Use the Rsync tool to synchronize rsync-axs/var/lib/docker/. $DOCKER _dir, which may take a long time, depending on the size of the/var/lib/docker
4 Modify the Fstab file to add the following line to the Fstab and mount the new location to the/var/lib/docker

#vim/etc/fstab

...
$DOCKER _dir/var/lib/docker None bind 0 0
5 re-mount:mount–a
6 Use the following command to check

#df-H/var/lib/docker/
Filesystem Size used Avail use% mounted on
/dev/sda6 110G 100G 9.9G 92%/var/lib/docker
7 Go to Container view our space
bash-4.1# DF-LHT
8 The partition size information in the host:

Root:/home/pika#df-lht
Filesystem Type Size used Avail use% mounted on
Udev Devtmpfs 3.9G 4.0K 3.9G 1%/dev
Tmpfs tmpfs 781M 1.3M 780M 1%/run
/dev/sda2 ext4 148G 14G 127G 10%/
None Tmpfs 4.0K 0 4.0K 0%/sys/fs/cgroup
None Tmpfs 5.0M 0 5.0M 0%/run/lock
None Tmpfs 3.9G 51M 3.8G 2%/RUN/SHM
None Tmpfs 100M 44K 100M 1%/run/user
/dev/sda6 fuseblk 110G 100G 9.9G 92%/media/pika/files
/dev/sda5 fuseblk 98G 78G 20G 80%/media/pika/softwares

[Modify storage location for Docker images]

from:http://blog.csdn.net/pipisorry/article/details/51330126

Ref


Docker Tutorial: Docker Image Export and migration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.