普拉多VX

人生一路,不问来时,不知归期

0%

docker 镜像导入导出

导出本地镜像

导出busybox镜像,也可以导出多个image到一个压缩文件

1
2
3
4
5
6
7
8
9
10
11
12
13
luodi@roddydeMacBook-Pro:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 08393e824c32 7 days ago 132MB
busybox latest 018c9d7b792b 2 weeks ago 1.22MB
cfcontorl 1.0.0 1a1b058798ce 4 weeks ago 97.6MB
<none> <none> 252cf95e99e7 4 weeks ago 97.6MB
ubuntu latest adafef2e596e 5 weeks ago 73.9MB
zookeeper latest 6982b35ff928 6 weeks ago 252MB
mysql 5.7.30 9cfcce23593a 2 months ago 448MB
mysql latest be0dbf01a0f3 2 months ago 541MB
wurstmeister/kafka latest f1905dce9659 3 months ago 431MB
mysql 8.0.19 0c27e8e5fcfa 3 months ago 546MB
luodi@roddydeMacBook-Pro:~$

使用docker save -o 导出镜像

1
luodi@roddydeMacBook-Pro:~$ docker save -o  ./busybox_image.gz  busybox:latest

导出多个image

1
luodi@roddydeMacBook-Pro:~$ docker save -o  ./all_image.gz  busybox:latest  nginx:latest

导入镜像到其他宿主机

上传busybox_imge.gz到其他宿主机

1
2
3
4
5
6
7
root@iZm5e7rjmq1tkuwoy8h8vuZ:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 08393e824c32 7 days ago 132MB
mysql 5.7 8679ced16d20 2 weeks ago 448MB
root@iZm5e7rjmq1tkuwoy8h8vuZ:~# ls busybox_image.gz
busybox_image.gz
root@iZm5e7rjmq1tkuwoy8h8vuZ:~#

使用docker load命令导入镜像压缩包

1
2
3
4
5
6
7
8
root@iZm5e7rjmq1tkuwoy8h8vuZ:~# docker load < busybox_image.gz 
514c3a3e64d4: Loading layer [==================================================>] 1.442MB/1.442MB
Loaded image: busybox:latest
root@iZm5e7rjmq1tkuwoy8h8vuZ:~# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 08393e824c32 7 days ago 132MB
busybox latest 018c9d7b792b 2 weeks ago 1.22MB
mysql 5.7 8679ced16d20 2 weeks ago 448MB

或者使用以下命令

docker load -i busybox_image.gz
docker load –input busybox_image.gz

使用镜像启动容器

1
2
3
4
5
6
root@iZm5e7rjmq1tkuwoy8h8vuZ:~# docker run --name=test4 -itd busybox  
b66d72fd79dc0940dc2c259bd38bcb5447bfd099405dea692a39ff6b9f6ce0ad
root@iZm5e7rjmq1tkuwoy8h8vuZ:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b66d72fd79dc busybox "sh" 4 seconds ago Up 2 seconds test4
root@iZm5e7rjmq1tkuwoy8h8vuZ:~#