目录

docker load 和 docker import 的区别

学校里的服务器因为安保原因隔绝了外网访问权限,因此要使用docker就需要从文件导入

预下载image

1
2
docker pull <image>:<tag>
docker save --output package.tar <image>:<tar> 

然后将tar包用scp、ftp等拷贝到目标服务器上

导入image

这里有一个小问题,docker help发现有俩类似的命令,docker importdocker load
下面分别来看看这俩的区别

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
$ docker import --help
Usage:  docker import [OPTIONS] file|URL|- [REPOSITORY[:TAG]]

Import the contents from a tarball to create a filesystem image

Options:
  -c, --change list       Apply Dockerfile instruction to the created image
  -m, --message string    Set commit message for imported image
      --platform string   Set platform if server is multi-platform capable

1
2
3
4
5
6
7
8
9
$ docker load --help
Usage:  docker load [OPTIONS]

Load an image from a tar archive or STDIN

Options:
  -i, --input string   Read from tar archive file, instead of STDIN
  -q, --quiet          Suppress the load output

可以看到import只是导入rootfs文件系统而load导入的是image,因此当前情况使用load更好。
(其实我试过了import,导入的image丢失了dockerfile里的所有东西,文件系统里的path啥的都没了,bash都起不来更不要说启动容器里的程序了

因此这里最后一步应该是

1
docker load -i package.tar