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

Mysql transaction concurrency problem solution

I encountered such a problem during development A...

XHTML Tutorial: The Difference Between Transitional and Strict

In fact, XHTML 1.0 is divided into two types (thr...

MySQL helps you understand index pushdown in seconds

Table of contents 1. The principle of index push-...

Problems and solutions when installing MySQL8.0.13 on Win10 system

Operating system: Window10 MySQL version: 8.0.13-...

The whole process record of Vue export Excel function

Table of contents 1. Front-end leading process: 2...

Limiting the number of short-term accesses to a certain IP based on Nginx

How to set a limit on the number of visits to a c...

Vue routing returns the operation method of restoring page status

Route parameters, route navigation guards: retain...

MySQL binlog opening steps

Binlog is a binary log file that is used to recor...

mysql IS NULL using index case explanation

Introduction The use of is null, is not null, and...

Solution for Vue routing this.route.push jump page not refreshing

Vue routing this.route.push jump page does not re...

mysql-8.0.16 winx64 latest installation tutorial with pictures and text

I just started learning about databases recently....