Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Docker Image

2025-03-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "how to use Docker Image". In daily operation, I believe many people have doubts about how to use Docker Image. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to use Docker Image". Next, please follow the editor to study!

Layer

The image is made up of layers. Image Layer is a general concept that can refer to the following:

Metadata described in JSON form

Changes to the file system described in layer

Image JSON

Each layer has a JSON data structure that describes the basic information of the Image, such as the date the image was created, the author, the parent image ID, and so on.

Image Filesystem Changeset

Each layer has an archive of files it adds, deletes, or modifies relative to the parent layer. Using a joint mount file system such as AUFS, a series of image layer can be presented as a single file system.

Image Parent

Most layer's metadata structures contain a parent field to specify its parent image. An Image contains a separate JSON metadata file and a series of file system changes relative to the parent image.

Image JSON Description {"id": "a9561eb1b190625c9adb5a9513e72c4dedafc1cb2d4c5236c9a6957ec7dfd5a9", "parent": "c6e3cedcda2e3982a1a6760e178355e8e65f7b80e4e5248743fa3549d284e024", "checksum": "tarsum.v1+sha256:e58fcf7418d2390dec8e8fb69d88c06ec07039d651fedc3aa72af9972e7d046b", "created": "2014-10-13T21:19:18.674353812Z", "author": "Alyssa P. Hacker & ltalyspdev@example.com>", "architecture": "amd64", "os": "linux", "Size": 271828 "config": {"User": "alice", "Memory": 2048, "MemorySwap": 4096, "CpuShares": 8, "ExposedPorts": {"8080/tcp": {}} "Env": ["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "FOO=docker_is_a_really", "BAR=great_tool_you_know"], "Entrypoint": ["/ bin/my-app-binary"] "Cmd": ["--foreground", "--config", "/ etc/my-app.d/default.cfg"], "Volumes": {"/ var/job-result-data": {}, "/ var/log/my-app-logs": {},} "WorkingDir": "/ home/alice",}}

Architecture string

The architecture of the host on which the mirrored binary is running.

Os string

The type of operating system on which the mirror is running.

ExposedPorts struct

The collection of ports exposed by the container running the mirror.

For example:

{"8080": {}, "53/udp": {}, "2356/tcp": {}}

Health can be of the following types:

"port/tcp"port/udp"port"

Among them. The default protocol is tcp protocol.

Entrypoint array of strings

A collection of commands to be executed when the container starts running.

Create Image Filesystem Changeset

First create an empty directory named Image ID as the root file system of the image. Take the mirror c3167915dc9d as an example:

C3167915dc9d/

Then create the corresponding directories and files:

C3167915dc9d/ etc/ my-app-config bin/ my-app-binary my-app-tools

The c3167915dc9d directory will be used as an entry for the packaged archive of the following files.

Etc/my-app-configbin/my-app-binarybin/my-app-tools

Once changes are made on the mirrored file system (add, delete, change), a new directory is created, named with a new ID, such as f60c56784b83, and initialized with a snapshot of the root file system of the parent mirror. In this way, the directory has exactly the same content as the original directory c3167915dc9d. As follows:

F60c56784b83/ etc/ my-app-config bin/ my-app-binary my-app-tools

The next modification is to add a configuration directory / etc/my-app.d, which contains a default configuration file. Similarly, changes are made to the directory my-app-tools to handle changes in the configuration layout. Then, the directory f60c56784b83 looks like this:

F60c56784b83/ etc/ my-app.d/ default.cfg bin/ my-app-binary my-app-tools

The above reflects the deletion of / etc/my-app-config and the creation of / etc/my-app.d/default.cfg. / bin/my-app-tools will also be replaced by newly modified ones. Before committing the directory to changeset, because it has a parent image, it is first compared with the directory tree f60c56784b83 of the parent image to find out all the modified files. The changeset is as follows:

Added: / etc/my-app.d/default.cfgModified: / bin/my-app-toolsDeleted: / etc/my-app-config

A packaged archive containing only the changeset is created. The file name is .wh. As the prefix file is "whiteout" file, it is important to note that it is not allowed to create an image root file system that contains "whiteout" file. The packaged archive of f60c56784b83 is as follows:

/ etc/my-app.d/default.cfg/bin/my-app-tools/etc/.wh.my-app-configCombined Image JSON + Filesystem Changeset Format

The structure that contains the complete information about Image is as follows:

Repository names/tags

All image layer JSON files

All tar archives of each layer filesystem changesets

Take library/busybox as an example:

. ├── 5785b62b697b99a5af6cd5d0aabc804d5748abbb6d3d07da5d1d3795f2dcc83e │ ├── VERSION │ ├── json │ └── layer.tar ├── a7b8b41220991bfc754d7ad445ad27b7f272ab8b4a2c175b9512b97471d02a8a │ ├── VERSION │ ├── json │ └── layer.tar ├── a936027c5ca8bf8f517923169a233e391cbb38469a75de8383b5228dc2d26ceb │ ├── VERSION │ ├── json layer.tar f60c56784b832dd990022afc120b8136ab3da9528094752ae13fe63a2d28dc8c VERSION json layer.tar repositories

For a full Image, it contains one or more directories named after Layer ID, each containing three files:

VERSION-The schema version of the json file

Json-The JSON metadata for an image layer

Layer.tar-The Tar archive of the filesystem changeset for an image layer.

Repositories is a JSON file that describes mirrored name and tag.

Loading an Image Filesystem Changeset

1. Find the root ancestor according to the parent ID of Image, that is, the Image without parent ID.

2, for each image layer, start from the root directory, from top to bottom, extract the file system changeset archive of each layer as the root file system of the later container.

Extract the contents of each archive.

Re-traverse the directory tree and delete all with .wh. A file as a prefix.

At this point, the study on "how to use Docker Image" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report