Docker mirror operation of Docker

1. Get the mirror

By using docker [image] pullto download the image from the image source Docker Hub commands directly. The format of the command is

docker [image] pull NAME [:TAG] 
  • NAME is the name of the mirror warehouse (used to distinguish between mirrors)
  • TAG is the label of the mirror image (usually used to indicate version information).

Normally, describing an image needs to include " name + label " information.
For Docker images, if you do not specify the TAG explicitly, the latest tag will be selected by default, which will download the latest version of the image in the warehouse.

Generally speaking, the latest tag of a mirror means that the content of the mirror will track the changes of the latest version, and the content is unstable. Therefore, from the perspective of stability, do not ignore the label information of the mirror or use the default latest-marked mirror in the production environment

If you download from an unofficial warehouse, you need to specify the complete warehouse address before the warehouse name. For example, to download the ubuntu:18.04 image from the mirror source of NetEase Hive, you can use the following command, and the name of the downloaded image ishub.c.163.com/public/ubuntu:18.04

$ docker pull hub.c.163.com/public/ubuntu:18.04

The options supported by the pull subcommand mainly include:

  • -a, --all-tags=true|false: Whether to get all the images in the warehouse, the default is No;
  • --disable-content-trust: Cancel the content verification of the mirror, the default is true.
    In addition, sometimes it is necessary to use the image proxy service to speed up the Docker image acquisition process, which can be added --registry-mirror=proxy_URLto the Docker service startup configuration to specify the image proxy service address (such as https://registry.docker-en.com)

2. View mirror information

1. Use the images command to list images

Use the docker imagesor docker image lscommand to list the basic information of the existing mirrors on the local host.
Insert picture description here

  • From which warehouse, such as ubuntuexpress ubuntuseries of base image;
  • The label information of the mirror, such as 18.04, latest, indicates different version information. The label is only a mark, and cannot identify the content of the mirror;
  • The ID of the mirror (uniquely identifying the mirror): If the IDs of the two mirrors are the same, it means that they actually point to the same mirror, but have different label names;
  • Creation time, indicating the last update time of the mirror;
  • Mirror size, good mirrors are often smaller in size.

The images subcommand mainly supports the following options, and users can try it by themselves:

  • -a, --all true | false: List all (including temporary files) image files, the default is No;
  • --digestS=true|false: List the digital summary value of the mirror, the default is No;
  • -f, --filter=[] : Filter the listed mirrors, such as dangling=rue only show mirrors that are not used; you can also specify mirrors with specific labels, etc.;
  • --format="TEMPLATE" : Control the output format, such as .ID for ID information, .Repository for warehouse information, etc.;
  • --no-trunec=true|false: Whether to cut off the too long part of the output result, such as the ID information of the mirror, the default is yes;
  • -q, --quiet=true|false: Only output ID information, default is No.

Wherein further support options for controlling the output, such as -f. --filter=[], --no-trune=true|false, -q, --quie=true|falseand the like.
More subcommand options can also be viewed through man docker-images.

2. Use the tag command to add mirror tags

In order to facilitate the use of a specific mirror in subsequent work, you can also use docker tagcommands to
add new tags to the local mirror arbitrarily. For example, to add a new myubuntu:latestmirror tag:

docker tag ubuntu:latest myubuntu:latest

myubuntu:latestThe ID of the mirror ubuntu:latestis exactly the same, they actually point to the same mirror file, but the alias is different. docker tagThe label added by the command actually acts like a link.

3. Use the inspect command to view detailed information

Use the docker [image] inspectcommand to get the detailed information of the image, including the producer, adaptive architecture, digital abstracts of each layer, etc.:
Insert picture description here

4. Use the history command to view the mirror history

Since the image file is composed of multiple layers, how do you know the specific content of each layer? At this time, you can use the historysub-command, which will list the creation information of each layer. Insert picture description here
Note that the command is automatically cut off too long, you can use the aforementioned --no-truncoption to output full command.

3. Search mirror

Use docker searchthe command can search Docker Hub official repository mirroring. The syntax is docker search [option] keyword.
The supported command options mainly include:

  • -f,: --filter filterfilter output content;
  • --format string: Format the output content;
  • --limit int: Limit the number of output results, the default is 25;
  • --no-trunc: Do not cut the output result.

Insert picture description here
Many mirrors containing keywords are returned, including the mirror name, description, number of favorites (indicating the popularity of the mirror), whether it is officially created, whether it is automatically created, etc. The default output results will be sorted by star rating .

4. Delete and clean up the image

1 Use tags to delete images

Use docker rmior a docker image rmcommand to delete the image, the format command docker rmi IMAGE [IMAGE ... ], which may be IMAGE tag or ID.
Support options include:

  • -f,: -forcedelete the image forcefully, even if there are containers that depend on it;
  • -no-prune: Do not clean up unlabeled parent mirrors.

When the same image has multiple tags, the docker rmicommand only deletes the specified tags in the multiple tags of the image, and does not affect the image file.

2. Use the mirror ID to delete the mirror

When using the docker rmicommand and back to keep mirrored ID (may be able to distinguish partial ID string prefix), it will first try to remove all tag points to the mirror, and then delete the image file itself.
Insert picture description here

If you want to forcibly delete an image, you can use the -f parameter; it
is generally not recommended to use the -f parameter to forcibly delete a container-dependent image. The correct approach is to delete all containers that depend on the image first, and then delete the image.

3. Clean up the image

After using Docker for a period of time, some temporary image files and some unused images may be left in the system, which can docker image prunebe cleaned up by commands.
Support options include:

  • -a,: -alldelete all useless mirrors, not just temporary mirrors;
  • -filter filter: Only clean the mirrors that meet the given filter;
  • -f,: -forcedelete the mirror forcefully without prompting for confirmation.

5. Create a mirror

1. Create based on existing containers

The main method is to use the docker [container] commitcommand.
The command format is docker [container] commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]], the main options include:

  • -a,: --author=" "author information;
  • -c --change=[],: Execute Dockerfle instructions when submitting, including CMD|ENTRYPOINT|ENV|EXPOSE|LABEL|ONBUILD|USER|VOLUME|WORKDIRetc.;
  • -m,: --message=" "submit message;
  • -p,: --pause=truePause the container when submitting.

2. Import based on local template

Users can also directly from a mirror image of an operating system template file leaders, mainly used docker [container] importcommands. The command format is docker [image] import [OPTIONS] file|URL|-[REPOSITORY[:TAG ] ]
to be imported directly into a mirror, you can use OpenVZ templates provided to create, or to create a mirror image of the other exported templates. The download address of the OPENVZ template is http://openvz.org/Download/templates/precreated.

3. Create based on Dockerfile

Creating based on Dockerfile is the most common way. Dockerfile is a text file that uses given instructions to describe the process of creating a new image based on a parent image.
The process can be used to create the mirror docker [image] buildcommand after successful compilation will be more of a local python: 3 Mirror:
Insert picture description here

6. Save and load images

1. Save image

If you want to export the image to a local file, you can use the docker [image] savecommand. The command supports -o, -output stringparameters, and exports the image to the specified file.

For example, deriving the local ubuntu: 18.04 mirror file ubuntu_18.04.tar, as shown below:
Insert picture description here
Thereafter, the user can copy ubuntu 18.04.tarsharing the image file to others.

2. Load the image

You can use docker [image] loadtar file is exported again lead people to the local image library. Support -i, -input stringoptions, read mirror content from specified file.

7. Upload mirror

You can use the docker [image] pushcommand to upload the image to the warehouse, the default upload Docker Hub official repository (login required). The command format is docker [image]push NAME [:TAG] | [REGISTRY_HOST [ :REGISTRY_PORT] / ]NAME [:TAG ].
Users can upload self-made images after registering on the Docker Hub website.

For example, a user user upload a local test:latestmirror, you can add a new label user / test: latest, and then use the docker [image ] pushcommand to upload the image:
Insert picture description here
The first time you upload will be prompted to enter your login information or register, login information to be recorded to a local ~/.dockerdirectory under.

Guess you like

Origin blog.csdn.net/weixin_44826356/article/details/109323268