# 保存镜像为压缩包
# 保存镜像的格式:
docker save [镜像名称|镜像ID] > [包名称]
[root@Centos7 ~]# docker save 7731472c3f2a > apline.tar
[root@Centos7 ~]# ll
-rw-r–r–. 1 root root 5888000 Mar 18 17:36 apline.tar
[root@Centos7 ~]# docker save -o apline-two.tar 7731472c3f2a
[root@Centos7 ~]# ll
total 148692
-rw-r–r–. 1 root root 5888000 Mar 18 17:36 apline.tar
-rw——-. 1 root root 5888000 Mar 18 17:37 apline-two.tar
# 导入镜像的格式:
docker load < [包名称]
[root@Centos7 ~]# docker load < apline.tar
c04d1437198b: Loading layer [========================================>] 5.88MB/5.88MB
Loaded image ID: sha256:7731472c3f2a25edbb9c085c78f42ec71259f2b83485aa60648276d408865839
[root@Centos7 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> 7731472c3f2a 2 months ago 5.61MB
# 注:save/load保存镜像无法自定义镜像名称,save保存镜像时如果使用ID保存则load导入镜像无名称,使用名称导入时才有名称。
[root@Centos7 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest b97242f89c8a 2 months ago 1.23MB
[root@Centos7 ~]# docker save busybox:latest > busybox.tar
[root@Centos7 ~]# ll
total 150120
-rw-r–r–. 1 root root 1459200 Mar 18 17:43 busybox.tar
[root@Centos7 ~]# docker rmi b97242f89c8a
Untagged: busybox:latest
Untagged: busybox@sha256:c5439d7db88ab5423999530349d327b04279ad3161d7596d2126dfb5b02bfd1f
Deleted: sha256:b97242f89c8a29d13aea12843a08441a4bbfc33528f55b60366c1d8f6923d0d4
Deleted: sha256:0064d0478d0060343cb2888ff3e91e718f0bffe9994162e8a4b310adb2a5ff74
[root@Centos7 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
[root@Centos7 ~]# docker load < busybox.tar
0064d0478d00: Loading layer [==================================================>] 1.45MB/1.45MB
Loaded image: busybox:latest
[root@Centos7 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest b97242f89c8a 2 months ago 1.23MB