Docker export/import images

If the server network is not good or the image cannot be pulled, you can only pull the image on another machine with a better network, export it as a file, download and upload it to a machine with a bad network, and then export it from the file. The docker image can also be used on a machine with a bad network.

First use docker images to view the local image and find its image id. There are two ways to import/export, and the two methods cannot be mixed. Otherwise, although the import does not prompt an error, it will prompt a failure when starting the container, and there is an imported image. Problems such as loss of environment variables, as shown in the figure:
insert image description here
1. Method 1 (recommended)

We can use the save and load commands to export the image to the host through the image id, the command is as follows:

docker save -o coredns.tar k8s.gcr.io/coredns:1.3.1

Then upload the exported image file to the host with poor network, execute the following command to import the image, the command is as follows:

$ docker load < coredns.tar

2. Method 2

We can also use the export and import commands to perform import/export operations. The export commands are as follows:

$ docker export eb516548c180 > coredns.tar

Copy
We will import the above coredns.tar.gz image to another node with poor network, the command is as follows (choose one of the two):

$ docker import /usr/local/coredns.tar
$ cat coredns.tar | docker import - k8s.gcr.io/coredns:1.3.1(镜像名自己定义)

Then execute the following command to check whether the import is successful, the command is as follows:

$ docker images

The node image list after the import is successful, as shown in the figure:
insert image description here
the introduction of Docker export/import image is now complete.

Guess you like

Origin blog.csdn.net/weixin_42857718/article/details/131192738