[docker series] detailed docker image management commands

insert image description here

1. Domestic Docker image warehouse

For reasons that everyone knows, the download speed of pull images from foreign docker repositories is actually very slow. Some domestic first-tier manufacturers and docker officials have provided some docker image repositories for free in China, and the download speed of using domestic image repositories will be greatly improved. E.g:

  • Chinese registry mirror officially provided by Docker
  • Alibaba Cloud Accelerator
  • DaoCloud Accelerator

We take the Chinese registry mirror officially provided by Docker as an example to explain the configuration method of the domestic mirror warehouse source. /etc/docker/daemon.jsonModify the content of the file to the following content, if the file does not exist, create a new one

{
    
    
"registry-mirrors":["https://registry.docker-cn.com"]
}

After the configuration is complete, restart the docker service

sudo systemctl restart docker

Go to download the pull mirror again, you will find that it is much faster than before. It's that simple!

3. Search mirror

There are many official images and high-quality images uploaded by third parties on Docker Hub . The following will introduce how to search and obtain these images.

  • The first way is to search for mirrors directly on the Docker hub. For example, when I search for a redis mirror, the green shield below is the mirror provided by the official redis, and the security and stability are guaranteed.

  • The second way can be used docker searchto search for mirrors,

We can also use the command to search for mirrors. For example, we need a tomcat image as our web service. We can use
the docker search command to search tomcat to find a suitable image for us.

docker search redis

The record whose OFFICIAL field value is OK is the official image.

Fourth, pull the mirror

The command to get the image from the Docker image repository is docker pull. The command format is:

docker pull [选项] [Docker Registey 地址[:端口号]/] 镜像名[:标签]

The specific options can be seen through the docker pull --help command. Here we talk about the format of the image name.

  • Docker image warehouse address: The format of the address is generally <域名/IP>[:端口号]. If you use the default mirror repository, you don't need to write the repository address, such as the configuration in the first section of this article.
  • Image name: The image name consists of two parts <用户名>/<软件名>. Generally speaking, the images provided by the official software generally do not have user names.

Example: Get the latest version of redis image through docker pull

docker pull redis:latest

Equivalent to

docker pull redis

5. List mirrors

To list downloaded images, use the docker image ls command.

docker images   //等同于docker image ls

  • REPOSITORY: repository and mirror name
  • TAG: Tag and version number
  • IMAGE ID: Image ID, the unique identifier of the image
  • CREATED: The build time of the image
  • SIZE: The size of the image file

6. The dangling mirror

In the mirror list, there may be a special mirror that has neither the repository name/mirror name nor the label/version number, both of which are displayed <none>. This mirror is usually called a dangling mirror , as shown in the following entry shown.

What is the reason for the dangling mirror?
In fact, the dangling image has the image name and label version number name when it is first pulled and downloaded. For example, redis officially released a docker image version 6.0. After a period of time, it was found that the 6.0 version of the image may have security problems, so it was rebuilt. A version 6.0 image.
The mirror name redis and the TAG of 6.0 are both occupied by the newly released mirror, and the mirror of the old version loses the mirror name and label and becomes a dangling mirror.

Generally speaking, the dangling image has lost its value and can be deleted at will. Use the following command to delete:

docker image prune

Seven, delete the local mirror

The following two syntaxes can complete the operation of mirror deletion:

docker rmi [选项] <镜像1> [<镜像2>.....]
docker image rm <镜像1>  [<镜像2>.....]

In the above syntax, the image ID and image name can be used as the unique identifier of the image to delete the image.

It should be noted that before deleting an image, you must confirm that the deleted image is not used by any container, otherwise it cannot be deleted.

As shown below, delete the response result of the hello-world image.

# docker rmi hello-world
Untagged: hello-world:latest
Untagged: hello-world@sha256:bfea6278a0a267fad2634554f4f0c6f31981eea41c553fdf5a83e95a41d40c38
Deleted: sha256:feb5d9fea6a5e9606aa995e879d862b825965ba48de054caab5ef356dc6b3412
Deleted: sha256:e07ee1baac5fae6a26f30cabfe54a36d3402f96afda318fe0a96cec4ca393359

Eight, mirror import and export

Use the save subcommand to save the image of the local repository as a tar file in the current directory.

docker save -o <自定义包名>.tar <镜像名称>

For example, the following command will export the hello-world image as a helloworld.tar and store it in the current directory

docker save -o helloworld.tar hello-world

We can import the hello-world image on another server. The import method is as follows:

Import method one (do not output detailed information) :

# docker load -i helloworld.tar

Import method two (output details) :

# docker load < helloworld.tar

The image export and import function can be used for image backup, and this tar package can also be used to transfer image files in companies that do not have an image repository.

insert image description here

Guess you like

Origin blog.csdn.net/hanxiaotongtong/article/details/123932133