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

What is the difference between Docker and container image

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

Share

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

This article shows you the difference between Docker and container image, the content is concise and easy to understand, can definitely brighten your eyes, through the detailed introduction of this article, I hope you can get something.

For many people who are new to container technology, it is not easy to figure out the difference and relationship between container, container image and Docker.

Let's first look at containers and container images. For example, execute the command line docker search nginx, and the records of the search results are container images.

The so-called mirror image is a static concept. A mirror image consists of several read-only layer layers.

On the left of the image above is the internal implementation details of the Docker image. We can see that multiple read-only layers are stacked together, and the layers are associated with each other through pointers. These layers can be accessed on the file system of the host running Docker.

Linux's Unified File system (union file system) technology combines these superimposed read-only layers into a single file system, which provides a unified perspective for these read-only layers, thus hiding the existence of multiple layers for Docker users.

From the perspective of Docker users, there is only one file system for a Docker image, as shown on the right side of the figure above.

The design of these file systems are Docker implementation details, in general we do not need to delve into. But if you are curious enough, use the command sudo tree to browse to the directory / var/lib/docker:

For example, I use the command docker images to browse and download to the local docker image:

One of the images, called jerry-nginx, is a web application. All its contents can be found in this directory under the / var/lib/docker directory:

After talking about the container image, let's take a look at the container.

Like the container image, the container is also a superposition of several layers. the only difference is that the top layer of all read-only layers is a readable and writable layer, as shown in the green illustration above.

Beginners can remember this simple formula: container = container image + readable and writable layer

If we look at the list of all containers on the machine with the command docker ps-- all, we will find that some containers are running and some are exiting.

Therefore, a running container (running container) contains a read-write file system plus isolated process space.

The process in the container can modify, delete, create and so on the files in the read-write file system.

Each layer in the image can actually be found in the containers subdirectory of the docker folder:

Each red folder in the image above represents a layer in the image, and the blue file contains the running log files of that layer, or network-related configurations, and so on.

Do an experiment:

After the execution of the ubuntu container, the find /-name i042416.txt file is used, which indicates that the docker runtime can write to the host's file system.

Here are a few commonly used confusing commands.

Docker create

Take a look at its help documentation first:

Try the following:

Generate an output id:

7ee10851c3f1e53bbd35e5f196f34de560afa1a20d9bf1ced587630dbcda877b

The status of the container created by create is changed to created:

The docker create command creates a new readable and writable layer for the container image passed in through the command line, resulting in a new container instance:

Then execute docker start, type the container instance ID created by docker create, and start the container instance.

Docker run is actually a version of the two commands docker create and docker start.

The above is what is the difference between Docker and container images. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

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