Let's talk about the difference between containers and images in Docker

Let's talk about the difference between containers and images in Docker

What is a mirror?

An image can be seen as a file system composed of multiple image layers (implemented by the UnionFS and AUFS file union system). An image layer can also be simply understood as a basic image, and each image layer is superimposed in the form of pointers.

What is a container?

The definition of a container is almost identical to that of an image, and is also a unified view of a stack of layers. The only difference is that the top layer of the container is readable and writable. Key points: Container = Image + Read/Write Layer, and the definition of container does not mention whether to run the container.

Today, let’s put aside the principles and the underlying principles. A simple explanation of the difference between containers and images in Docker.

For beginners, it may be a bit confusing to just get started with Docker, especially images and containers. In fact, we can understand that the relationship between images and containers is one-to-many.

The following figure shows an incorrect demonstration. Why is it wrong? Because you can indeed start three containers with one image, but the names of these three containers cannot be the same

Correct example (some people ask what is the difference between this and the above picture. In the above picture, the names are the same: container = container = container. Here, the names are container a != container b != container c )

So we can run three containers through one image. The image is packaged by others in the image warehouse, and we just need to download it. But we need to bring the version number when downloading the image. Just like when we download a jdk, the official website defaults to the latest version. If we want to download an older version, we have to enter the corresponding version.

How does an image run as a container? For example, msql, we download a mysql image.

docker pull mysql

Run the image to generate the mysql_zhangsan database (a database specifically for Zhang San)

[root@localhost ~]# docker run ‐p 3306:3306 ‐‐name mysql_zhangsan ‐e MYSQL_ROOT_PASSWORD=123456 ‐d mysql 
ad10e4bc5c6a0f61cbad43898de71d366117d120e39db651844c0e73863b9434

-p 3306:3306 : port mapping

--name mysql_zhangsan: Name this container mysql_zhangsan (this name is unique and cannot be repeated)

-e MYSQL_ROOT_PASSWORD=123456: The account for logging into this database is ROOT and the password is 123456

-d is created based on the mysql image we just pulled down.

Run the image to generate the mysql_lisi database (a database specifically for Li Si)

[root@localhost ~]# docker run ‐p 3307:3307 ‐‐name mysql_lisi ‐e MYSQL_ROOT_PASSWORD=123456 ‐d mysql 
ms10e4bcfdsf0f61cbad43898de71d366117d120dfs9db651844c0e73863b9968

-p 3307:3307: port mapping (port 3306 cannot be used because it is occupied by Zhang San's database)

--name mysql_lisi : Name this container mysql_lisi (this name is unique and cannot be repeated with mysql_zhangsan above)

-e MYSQL_ROOT_PASSWORD=123456: The account for logging into this database is also ROOT and the password is also 123456

-d is created based on the mysql image we just pulled down.

At this point, we have successfully created two different containers through one image. In this way, we can run two mysql on our computer. If we want to open another MySQL container, as long as the port and name are different, we can still create it based on the MySQL image we pulled.

The above is the detailed content of the difference between containers and images in docker. For more information about the difference between docker containers and images, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • Docker practice: error resolution when starting a container from a new image
  • How to modify the storage location of Docker default images and containers
  • How to modify the storage directory of the image container in Docker
  • Change the location of Docker default images and containers in CentOS 7
  • Summary of common Docker commands: installation, mirroring, and basic container operations
  • Docker Tips: Deleting Docker Containers and Images

<<:  50 Beautiful FLASH Website Design Examples

>>:  Understand the rendering process of HTML pages in preparation for learning front-end performance optimization (continued)

Recommend

Detailed description of mysql replace into usage

The replace statement is generally similar to ins...

Front-end JavaScript housekeeper package.json

Table of contents 1. Required attributes 1. name ...

How to implement a simple HTML video player

This article introduces the method of implementin...

Examples of clearfix and clear

This article mainly explains how to use clearfix a...

About Tomcat combined with Atomikos to implement JTA

Recently, the project switched the environment an...

How to add a disk in Vmware: Expand the disk

This article describes how to add or expand a dis...

MySQL master-slave configuration study notes

● I was planning to buy some cloud data to provid...

Summary of MySQL Undo Log and Redo Log

Table of contents Undo Log Undo Log Generation an...

7 skills that web designers must have

Web design is both a science and an art. Web desi...

An elegant way to handle WeChat applet authorization login

Preface When the WeChat mini program project invo...

Who is a User Experience Designer?

Scary, isn't it! Translation in the picture: ...

JavaScript+HTML to implement student information management system

Table of contents 1. Introduction 2. Rendering 3....