docker 的导出和导入

docker 的导出和导入

1. 导出导入 image

#查看已有的 images
$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
java                latest              e9de8c6faf15        7 days ago          641.9 MB
centos              latest              ce20c473cd8a        8 weeks ago         172.3 MB

#导出 image
$ docker save e9de8c6faf15 > java.tar

##导入 image
$ docker load < java.tar

2. 导入导出 Container

#查看所有 container
$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                    PORTS               NAMES
7691a814370e        ubuntu:14.04        "/bin/bash"         36 hours ago        Exited (0) 21 hours ago                       test
# 导出 container快照到本地文件
$ docker export 7691a814370e > ubuntu.tar

#从容器快照文件中再导入为镜像
$ cat ubuntu.tar | docker import - test/ubuntu:v1.0
$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED              VIRTUAL SIZE
test/ubuntu         v1.0                9d37a6082e97        About a minute ago   171.3 MB
2015-12-13 13:1012