Export / Import

Export a container’s filesystem as a tar archive.
将容器的文件系统导出为tar存档文件

只导出当前容器的信息

## 
#  Usage:
#    docker export [OPTIONS] CONTAINER
#  Options:
#    --output , -o   Write to a file, instead of STDOUT
 
$ docker export red_panda > latest.tar
$ docker export --output="latest.tar" red_panda

Import the contents from a tarball to create a filesystem image
从tarball中导入内容以创建文件系统镜像

是将当前容器 变成一个新的镜像

## 
#  Usage:
#    docker import [OPTIONS] file|URL|- [REPOSITORY[:TAG]]
#  Options:
#    --change , -c  Apply Dockerfile instruction to the created image
#    --message , -m  Set commit message for imported image

$ docker import exampleimage.tgz --message "New image imported from tarball" - exampleimagelocal:new

Save/Load

Save one or more images to a tar archive (streamed to STDOUT by default)
将一个或多个镜像保存到tar存档

保存镜像所有的信息-包含历史

## 
#  Usage:
#    docker save [OPTIONS] IMAGE [IMAGE...]
#  Options:
#    --output , -o   Write to a file, instead of STDOUT

$ docker save busybox > busybox.tar

$ docker save --output busybox.tar busybox
## 
#  You can even cherry-pick particular tags of an image repository.

$ docker save -o ubuntu.tar ubuntu:lucid ubuntu:saucy
## 
#  
[root@ec-k8s-m1 ~]# docker images
REPOSITORY                                                   TAG                 IMAGE ID            CREATED             SIZE
spark                                                        v2.3.2              9c672c188d7e        23 hours ago 

[root@ec-k8s-m1 spark]# docker save -o spark-v2.3.2.tar spark:v2.3.2 spark:v2.3.2

[root@ec-k8s-m1 spark]# ll -h
total 334M
-rw-------  1 root    root    334M Oct 31 15:32 spark-2.3.2.tar

Load an image from a tar archive or STDIN
从tar存档或STDIN加载镜像

## 
#  Usage:
#    docker load [OPTIONS]
#  Options:
#    --input , -i  Read from tar archive file, instead of STDIN
#    --quiet , -q  Suppress the load output

$ docker image ls

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

$ docker load < busybox.tar.gz

Loaded image: busybox:latest

$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
busybox             latest              769b9341d937        7 weeks ago         2.489 MB

$ docker load --input fedora.tar

Loaded image: fedora:rawhide

Loaded image: fedora:20

$ docker images

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
busybox             latest              769b9341d937        7 weeks ago         2.489 MB
fedora              rawhide             0d20aec6529d        7 weeks ago         387 MB
##
#  导入 spark-v2.3.2.tar 镜像

[root@ec-k8s-n1 spark]# docker load < spark-v2.3.2.tar 

0c3170905795: Loading layer [==================================================>]  3.584kB/3.584kB
ed6f0bd39121: Loading layer [==================================================>]   99.1MB/99.1MB
a659c7f40c43: Loading layer [==================================================>]  5.844MB/5.844MB
59983af52084: Loading layer [==================================================>]  234.9MB/234.9MB
a6a614c9dc62: Loading layer [==================================================>]  70.66kB/70.66kB
aebd98385dbf: Loading layer [==================================================>]  58.37kB/58.37kB
ed15fd2fc4f8: Loading layer [==================================================>]  26.11kB/26.11kB
0adf64250f69: Loading layer [==================================================>]   5.12kB/5.12kB
c14134bcf8d2: Loading layer [==================================================>]   3.96MB/3.96MB
11630c7ac125: Loading layer [==================================================>]  784.9kB/784.9kB
Loaded image: spark:v2.3.2

[root@ec-k8s-n1 spark]# docker images
REPOSITORY     TAG         IMAGE ID       CREATED          SIZE
spark          v2.3.2      9c672c188d7e   24 hours ago     346MB
......

参考资料:
https://docs.docker.com/engine/reference/commandline/