The Docker in My Eyes (ii) Image

Source: Internet
Author: User
Tags virtual environment docker hub

Docker Installation

How to install Docker See official website: Installation or Chinese guide.
However, I recommend using Curl on Linux because the source in Apt-get either has no Docker or has a lower version.

sudosudo-ssudo docker run hello-world

If the last command succeeds, Docker will work.
However, because of China's obvious national conditions, it is recommended to install it using the Daocloud service:

# curl -sSL https://get.daocloud.io/docker | sh

Well then it's best to configure the Daocloud accelerator, which is set mirror:

echo"DOCKER_OPTS=\"\$DOCKER_OPTS --registry-mirror=http://f9495414.m.daocloud.io\""sudo-asudo service docker restart
Image command

Image is the cornerstone of Docker, and the instructions for the command can be viewed directly from the official documentation: DOC
Common commands are:

$ # list all mirrors$ sudo docker images$ # Pull New Image$ sudo docker pull Hello-world$ # Tag a mirror, tag is like a reference count for a mirror$ sudo docker tag Hello-world myname/hello-world$ # push Mirror to Docker hub$ sudo docker push Myname/hello-world$ # Search for mirrors in Docker hub$ sudo docker search Ubuntu$ # Delete a mirror$ sudo docker rmi Hello-world$ # Remove the image named <none> (intermediate image that may not be successfully left in the build process or pull process)$ sudo docker images | Grep"<none>"| Tr-s"'| cut-f3-d" "| sudo parallel docker rmi {}
Image composition

Image is a basic unit that can be run, so what is the image that is displayed when we run Docker images?

Image inside is a layer of file system, called Union FS, Federated File system, you can attach several layers of directories together to become the same virtual file system. The directory structure of the filesystem is like the directory structure of Normal Linux, and Docker provides a Linux virtual environment through these files with the host's kernel. Each layer of filesystem we call layer layers, and the federated file system can set three permissions, read-only (readonly), read-write (ReadWrite), and write-down (whiteout-able) for each layer of file system, but each layer of the Docker image is read-only.

When the image is built, starting from a basic operating system, each build operation is equivalent to making a layer of modification, adding a layer of file system, layer by layer to overlay, the upper level of the changes will cover the bottom of the visibility of that location, it is easy to understand, as the upper layer to cover the bottom of the same. When you use it, you will only see a complete whole, you do not know how many layers there are, and it is unclear what changes are made to each layer. The structure is similar to this:

From a basic perspective, a typical Linux file system consists of two parts, Bootfs and Rootfs, bootfs (boot file systems) mainly contains bootloader and kernel,bootloader primarily for boot loading Kerne L, when the kernel is loaded into memory bootfs will be umount off. Rootfs (Root file system) contains standard directories and files such as/dev,/proc,/bin,/etc in a typical Linux system. See, is the most basic two-tier structure in Docker Image:

Different Linux distributions (such as Ubuntu and CentOS) differ in the ROOTFS layer, reflecting the difference in distribution:

The traditional Linux load Bootfs will first set the Rootfs to Read-only, then change the rootfs from Read-only to Read-write after the system self-test, then we can read and write on the rootfs. But Docker will not change Rootfs's read-only to Read-write after Bootfs self-test, but instead use the union mount (a mount mechanism of UnionFS) to load the other layers in the image into the previous Above the ROOTFS layer of read-only, each layer is a ROOTFS structure and read-only. So, we can't modify a layer in an existing mirror! Only when we create a container, that is, to instantiate the Docker image, the system allocates an empty layer of read-write rootfs to save the changes we made. The changes saved by a layer of layers are incremental, just like git.

Image structure

If we have a ubuntu:14.04 image, then we can save it as a tar file and observe:

? ~ sudo docker save-o ubuntu_image. TarUbuntu:14.04? ~ TAR-TF Ubuntu_image. Tar 428b411c28f0c33e561a95400a729552db578aee0553f87053b96fc0008cca6a/428B411c28f0c33e561a95400a729552db578aee0553f87053b96fc0008cca6a/version428B411c28f0c33e561a95400a729552db578aee0553f87053b96fc0008cca6a/json428B411c28f0c33e561a95400a729552db578aee0553f87053b96fc0008cca6a/layer. Tar435050075b3f881611b0f4c141bb723f38603caacd31a13a185c1a38acfb4ade/435050075B3f881611b0f4c141bb723f38603caacd31a13a185c1a38acfb4ade/version435050075B3f881611b0f4c141bb723f38603caacd31a13a185c1a38acfb4ade/json435050075B3f881611b0f4c141bb723f38603caacd31a13a185c1a38acfb4ade/layer. Tar6d4946999d4fb403f40e151ecbd13cb866da125431eb1df0cdfd4dc72674e3c6/6D4946999d4fb403f40e151ecbd13cb866da125431eb1df0cdfd4dc72674e3c6/version6D4946999d4fb403f40e151ecbd13cb866da125431eb1df0cdfd4dc72674e3c6/json6D4946999d4fb403f40e151ecbd13cb866da125431eb1df0cdfd4dc72674e3c6/layer. Tar9fd3c8c9af32dddb1793ccb5f6535e12d735eacae16f8f8c4214f42f33fe3d29/9Fd3c8c9af32dddb1793ccb5f6535e12d735eacae16f8f8c4214f42f33fe3d29/version9Fd3c8c9af32dddb1793ccb5f6535e12d735eacae16f8f8c4214f42f33fe3d29/json9Fd3c8c9af32dddb1793ccb5f6535e12d735eacae16f8f8c4214f42f33fe3d29/layer. TarRepositories

As we can see, the image in Ubuntu is actually a compressed file with 4 folders, which is actually 4 layers, one folder per layer, and one repositories file. More intuitive, you can extract to the folder, with the tree command to view:

 Ubuntu:14.04  tree. ├──< Span class= "Hljs-number" >428  b411c28f0c33e561a95400a729552db578aee0553f87053b96fc0008cca6a│├──json│├── Layer.tar  │└──version├──435050075  B3f881611b0f4c141bb723f38603caacd31a13a185c1a38acfb4ade│├──json│├──layer.tar
     │└──version├──6  D4946999d4fb403f40e151ecbd13cb866da125431eb1df0cdfd4dc72674e3c6│├──json│├──layer .tar  │└──version├──9  Fd3c8c9af32dddb1793ccb5f6535e12d735eacae16f8f8c4214f42f33fe3d29│├──json│├──layer .tar  │└──version└──repositories4  directories, 13  files  

It can be said that each folder has the same structure, which means that each layer is organized in the same way as the JSON, Layer.tar, and VERSION representations. Let's look at the repositories file, which is a JSON definition that holds three messages: the image name, tag, and tag corresponding to the layer (this layer is a summary of the ubuntu:14.04 layer).

?  ~  cat repositories {"ubuntu":{"14.04":"6d4946999d4fb403f40e151ecbd13cb866da125431eb1df0cdfd4dc72674e3c6"}}

Entering a folder, viewing the JSON file, is a JSON definition that holds a lot of information, mainly about the configuration information of the image, with the following brief structure:

And Layer.tar is also a package file, through the following can be seen, the inside is a class Linux file directory structure, save the changes made by this layer:

?435050075B3f881611b0f4c141bb723f38603caacd31a13a185c1a38acfb4ade TAR-TF Layer. TarEtc/etc/apt/etc/apt/apt. conf. D/etc/apt/apt. conf. D/docker-cleanetc/apt/apt. conf. D/docker-gzip-indexesetc/apt/apt. conf. D/docker-no-languagesetc/dpkg/etc/dpkg/dpkg. CFG. D/etc/dpkg/dpkg. CFG. D/docker-apt-speedupsbin/sbin/initctlsbin/initctl. DistribUsr/usr/sbin/usr/sbin/policy-rc. DVar/var/lib/var/lib/dpkg/var/lib/dpkg/diversionsvar/lib/dpkg/diversions-old

Finally, it should be noted that the layer is shared between the mirrors, different mirrors, for the same layer as the digest will only save one copy, in the form of tree inheritance, can be docker images -tree viewed:

? ~ sudo docker images-tree Warning:'-tree '  is deprecated, it'll be removed soon. See usage ... #略 ├─428B411c28f0VirtualSize:188.1mb│└─435050075b3fVirtualSize:188.3mb│└─9Fd3c8c9af32VirtualSize:188.3mb│└─6d4946999d4fVirtualSize:188.3MB Tags:ubuntu:latest, Ubuntu:14.04│└─cf73ddbcb12bVirtualSize:375.1mb│└─7cb6f45e653dVirtualSize:377.6Mb│└─c624e1a476d0VirtualSize:377.6mb│└─4b087f2af755VirtualSize:389.1mb│└─6940F969b4edVirtualSize:413.9mb│└─1bc2ae3e600bVirtualSize:414mb│└─c35a7b3ee359VirtualSize:414Mb│└─b4696f4e4d61VirtualSize:414mb│└─7413e661f075VirtualSize:414mb│└─9A2409206c78VirtualSize:414MB Tags:registry:latest ... #略

The Docker in My Eyes (ii) Image

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.