File system changes for the Docker file system and startup container

Source: Internet
Author: User
Tags diff json docker run docker toolbox

This article mainly introduces the Docker basic things, first introduced my implementation environment:
1. Windows 10 Official edition
1. Docker Toolbox
1. Docker version 1.8.2
1. Official Mirror Ubuntu:latest
Here we basically only say aufs/containers/graph these three directories.
1. Enter the Docker file system directory first

Ll/var/lib/docker #其中目录是这样的/var/lib/docker->/mnt/sda1/var/lib/docker/

Df-h # View Mount status

FileSystem Size Used Available use% mounted on
Tmpfs 896.6M 115.3M 781.3M 13%/
Tmpfs 498.1M 0 498.1M 0%/dev/shm
/DEV/SDA1 18.2G 300.1M 16.9G 2%/mnt/sda1
Cgroup 498.1M 0 498.1M 0%/sys/fs/cgroup
None 100.0G 42.1G 57.9G 42%/c/users
/DEV/SDA1 18.2G 300.1M 16.9G 2%/mnt/sda1/var/lib/docker/aufs


Ls-l/mnt/sda1/var/lib/docker/
Drwxr-xr-x 5 root 4096 Sep 01:59 aufs/# System mount directory, System-used AUFS
DRWX------2 root 4096 Oct 7 03:48 containers/# container File system
DRWX------7 Root 12288 Oct 7 03:48 graph/# Local Mirror
-rw-r--r--1 root root 15360 Oct 7 03:48 linkgraph.db
-RW-------1 root 7 03:48 REPOSITORIES-AUFS # Stores basic information about image
DRWX------2 root 4096 Oct 7 02:52 tmp/
drwx------2 root root 4096 Sep 02:01 trust/
drwx------2 root root 4096 Sep 01:59 volumes/
look at my local mirrors
Docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
Ubuntu latest 91e54dfb1179 6 weeks ago 188.4 MB
I have a local ubuntu:latest office image, and the short ID of image is 91e54dfb1179. Here's a note. Docker mirroring is made up of mirrored-layer file contents and JSON files.
1. Mirrored-layer files are stored in/var/lib/docker/aufs/diff
1. Local mirrored JSON files are stored under the/var/lib/docker/graph folder.

As shown in the image above, mirrored metadata is stored in the mirrored JSON file, such as the parent mirror ID

The mirror ID and hierarchy are stored in the/var/lib/docker/aufs/layers, and we know that the bottom image ID is d3a1f33e8a5a513092f01bb7eb1c2abf4d711e5105390a3fe1ae2248cfde1391
Layers

We look at container-level content

$ cd/var/lib/docker/aufs/diff/d3a1f33e8a5a513092f01bb7eb1c2abf4d711e5105390a3fe1ae2248cfde1391
$ ls

We have seen the Rootfs file directory as shown above, and this mirror as the root of the Images, we use the final mirror ubuntu:latest is on the basis of this image based on the relationship of each level dynamically added.

As pictured above, the mirror ID under/var/lib/docker/graph and mirrored JSON, look at the contents of the JSON file as follows:

All metadata, including all the parent mirror IDs, the commands executed on the parent mirror ID, and the build mirror ID, are included as shown in the figure above. When we start the container, we will step by step gradually from the rootfs to accumulate.
2. Start the container

Docker run-i-t Ubuntu bash
When we run the command above, the basic process is as follows:
1. It will first check whether we have a local ubuntu:latest image, and if so, load the mirror, which is what we mentioned earlier. 91e54dfb11794fad694460162bf0cb0a4fa710cfa3f60979c177d920813e267c.
2. To create the container, the program's CREATEROOTFS calls the CREATE function to create the Id-init folder under the Mnt and diff folders, then loads the dependent layers layer from the program's get function to the Id-init folder, sequentially, according to the hierarchy relationship 。 Only Id-init are writable, others are readable.
3. Call the CREATE function again to create the ID folder, create the ID folder and all the configuration files under the Containers folder, and then launch the container to mount the layers of the dependent containers into the ID folder, in turn.
When we operate inside the container, the log is stored in the/var/lib/docker/containers/id/id-json.log, as shown in

Above, we can see from the log that we have two parts for the container operation:
CD root
Touch 1.txt
Then we create the 1.txt file, recorded under/var/lib/docker/diff/id/root/, as shown below

This can be very simple to see the Docker hierarchy and data relations.

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.