Docker image management common operation code examples

Docker image management common operation code examples

Mirroring is also one of the core components of Docker. Mirroring is the basis for container operation, and container is the form of mirroring after operation. Generally speaking, an image is a read-only file that contains the environment and code necessary for a program to run. It uses a layered file system to add changes to each layer in the form of a read-write layer to the original read-only file.

The relationship between images and containers

The previous article has introduced the use of containers to readers. Careful readers may have discovered that when starting or creating a container, you must specify a mirror name or ID. In fact, the role played by the mirror at this time is the template of the container. Different mirrors can construct different containers. The following command:

docker run -itd --name nginx nginx

The last nginx in the command indicates the template required to create the container.

Mirrored Architecture

The bottom layer of the image is a boot file system (bootfs) image. The upper layer of bootfs is called the root image. Generally speaking, the root image is an operating system, such as Ubuntu, CentOS, etc. The user's image must be built on the root image. On top of the root image, the user can build various other images. From the above introduction, readers can see that the essence of a mirror is actually a collection of files, and the layer-by-layer structure is somewhat similar to Git.

Copy-on-write mechanism for mirroring

When you specify a container to create an image through the docker run command, you actually create an empty readable and writable file system hierarchy on the image. You can treat this file system hierarchy as a temporary image, and the template image referred to in the command can be called the parent image. The contents of the parent image are mounted in read-only mode. The container will read the contents of the shared parent image. All modifications made by the user are in the file system and will not have any impact on the parent image. Of course, users can use other means to make the changes persistent in the parent image, which we will introduce in detail later.

Check

docker images

Users can view all local images through the docker images command


There are five parameters here:

1.REPOSITORY

Warehouse name. Warehouses are generally used to store images of the same type. The name of the warehouse is specified by its creator. If not specified, then . Generally speaking, warehouse names have the following different forms.

  • [namespace\ubuntu]: This repository name consists of the namespace and the actual repository name, separated by \. When a developer creates a user on Docker Hub, the username is the default namespace. This namespace is used to distinguish different users or organizations registered on Docker Hub (similar to the role of usernames on GitHub). If readers want to upload their own images to Docker Hub for others to use, they must specify a namespace.
  • [ubuntu]: This type of repository name only has a repository name. For this type of repository name without a namespace, it can be considered to belong to the top-level namespace. The repository in this space is only used for official images and is managed by Docker officials, but is generally authorized to third parties for development and maintenance. Of course, users can also use this naming method for images they create themselves, but they will not be able to be uploaded to Docker Hub for sharing.
  • [hub.c.163.com/library/nginx]: This method of specifying the URL path is generally used for naming images that are not on the Docker Hub. For example, an image provided by a third-party service provider or an image center built by the developer himself can all be named in this way.

2.TAG is used to distinguish different images of the same repository, the default is latest

3.IMAGE ID is a unique identifier for the image

4.CREATED The creation time of the image

5.SIZE indicates the image size

Use the docker images command to view all local images. If there are too many images, you can match them using wildcards, as follows:


If you need to view detailed information about the image, you can also use the docker inspect command mentioned above to view the download

When the user executes the docker run command, it will automatically download the relevant image from Docker Hub. This will not be demonstrated again. Developers can also use the search command to search for images that meet the requirements on Docker Hub, as follows:


in:

  • NAME: indicates the name of the image
  • DESCRIPTION: A brief description of the image.
  • STARS: indicates the user's rating of the image. The higher the rating, the safer it is to use.
  • OFFICIAL: Is it an official image?
  • AUTOMATED: Whether automatic build is used

The speed of downloading after executing the docker run command will be a bit slow. If you want the command to execute quickly, you can use the docker pull command to download the image before executing it, and then run it.


Run the command as follows:

delete

The image can be deleted through the docker rmi command. The parameter is the image ID or image name. There can be multiple parameters, separated by spaces, as follows:

Sometimes, you cannot delete an image. Most of the time, this is because the image is dependent on a container. In this case, you need to delete the container first, and then you can delete the image.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • .NETCore Docker implements containerization and private image repository management
  • Docker private repository management and deletion of images in local repositories
  • Analysis of Docker's method for creating local images
  • Briefly describe how to install Tomcat image and deploy web project in Docker
  • The simplest implementation of spring boot packaging docker image
  • How to generate a docker image and complete container deployment in a spring boot project
  • How to deploy Vue project using Docker image + nginx
  • Detailed explanation of the latest IDEA process of quickly deploying and running Docker images
  • Detailed explanation of the use of DockerHub image repository

<<:  Detailed tutorial on installing mysql8.0.22 on Alibaba Cloud centos7

>>:  JavaScript realizes the effect of mobile modal box

Recommend

Examples of using provide and inject in Vue2.0/3.0

Table of contents 1. What is the use of provide/i...

What is Software 404 and 404 Error and what is the difference between them

First of all, what is 404 and soft 404? 404: Simpl...

Solution to MySQL unable to read table error (MySQL 1018 error)

1. Error reproduction I can access the MySQL data...

Self-study of MySql built-in functions knowledge points summary

String functions Check the ascii code value of th...

JavaScript's unreliable undefined

undefined In JavaScript, if we want to determine ...

Docker online and offline installation and common command operations

1. Test environment name Version centos 7.6 docke...

Specific use of stacking context in CSS

Preface Under the influence of some CSS interacti...

5 tips for writing CSS to make your style more standardized

1. Arrange CSS in alphabetical order Not in alphab...

Sharing of SVN service backup operation steps

SVN service backup steps 1. Prepare the source se...

CSS scroll-snap scroll event stop and element position detection implementation

1. Scroll Snap is a must-have skill for front-end...

The difference between MySQL execute, executeUpdate and executeQuery

The differences among execute, executeUpdate, and...