“This is the fifth day of my participation in the August More Text Challenge.

In practice, image import and export are mainly for the purpose of docker image installation and deployment when access to the Internet is unavailable. Docker provides Docker save and Docker load commands to save the image as a file, transfer it to another location, and load it in. Offline installation docker can refer to another article: https://juejin.cn/post/6992341941656485924

1. List mirrors

List the mirror

$ docker image ls
Copy the code

View the space occupied by mirrors, containers, and data volumes

$docker system df TYPE TOTAL ACTIVE SIZE RECLAIMABLEImages 24 0 1.992GB 1.992GB (100%)Containers 10 62.82MB 62.82MB Local Volumes 9 0 652.2MB 652.2MB Build Cache 0B 0BCopy the code

2. Export the image

For example, save this SRS image:

$Docker Image ls SRS REPOSITORY TAG Image ID CREATED SIZE SRS latest baa5D63471EA 5 weeks ago 4.803 MBCopy the code

Save the image:

$ docker save srs -o filename.xxx
$ file filename.xxx
filename: POSIX tar archive
Copy the code

Here filename. XXX can be any name + any suffix, such as srs-latest.tar, but the file is essentially an archive

To use gzip compression:

$ docker save srs | gzip > srs-latest.tar.gz
Copy the code

Overrides if it has the same name (without warning)

3. Import the image

Then we copied the srs-latest.tar.gz file to another machine and imported the image:

$ docker load -i srs-latest.tar.gz
======================================>
Loaded image: srs:latest
Copy the code

This mode is used to load images offline, but is not recommended. The repository Docker Registry is preferred for image migration.

4. Delete the mirror

To delete a local image, run the docker image rm command in the following format:

$docker image rm [options] < image 1> [< image 2>...Copy the code

Batch clear temporary image files

$ docker image prune
Copy the code

5. Mirror warehouse

You can use a mirror warehouse if you have a built image that needs to be rebuilt every time you find it troublesome

A warehouse is a centralized place for storing images. A confusing concept is Registry, which is actually a concrete server that manages warehouses. There can be multiple repositories on each server, and multiple images under each repository. In this respect, a warehouse can be thought of as a specific project or catalog.

For example, for the warehouse address registry.cn-hangzhou.aliyuncs.com/d-cloud/srs

  • Registry.cn-hangzhou.aliyuncs.com is the registration server address
  • D-cloud is the repository name
  • SRS is the mirror

Most of the time, it is not necessary to make a strict distinction between the two concepts.

Every time you build an image, it takes a lot of time. Once you have a repository, you don’t need to build again. You can just download the image. You can use the Docker pull command to download it and deploy it locally.