1.保存容器为新镜像 命令:docker commit -m “” -a “” [CONTAINER ID] [给新的镜像命名]
docker commit -a "runoob.com" -m "my apache" a404c6c174a2 bb:v1
2.保存镜像为文件 命令:docker save -o 要保存的文件名 要保存的镜像
例子:
[root@iZbp16cdvzk4rhl0vn1gedZ ~]# ls aaa.cap install.sh mobile-1.0.0-SNAPSHOT.jar sa_recovery.log [root@iZbp16cdvzk4rhl0vn1gedZ ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE bb v1.0 3b8d26737bcb 10 minutes ago 202MB centos latest 9f38484d220f 3 weeks ago 202MB java latest d23bdf5b1b1b 2 years ago 643MB [root@iZbp16cdvzk4rhl0vn1gedZ ~]# docker save -o cc.tar bb:v1.0 [root@iZbp16cdvzk4rhl0vn1gedZ ~]# ls aaa.cap cc.tar install.sh mobile-1.0.0-SNAPSHOT.jar sa_recovery.log
3.导入文件生成镜像 命令:docker load --input 文件 或者 docker load < 文件名
docker load --input 文件 或者 docker load < 文件名 例子:
[root@iZbp16cdvzk4rhl0vn1gedZ ~]# docker rm -f aa aa [root@iZbp16cdvzk4rhl0vn1gedZ ~]# docker rmi centos:latest bb:v1.0 Untagged: bb:v1.0 Deleted: sha256:3b8d26737bcb99aa12ef55c6e9620720b0ad85ecdee9cd52fbb5d5e1a2da2591 Untagged: centos:latest Untagged: centos@sha256:8d487d68857f5bc9595793279b33d082b03713341ddec91054382641d14db861 Deleted: sha256:9f38484d220fa527b1fb19747638497179500a1bed8bf0498eb788229229e6e1 Deleted: sha256:d69483a6face4499acb974449d1303591fcbb5cdce5420f36f8a6607bda11854
[root@iZbp16cdvzk4rhl0vn1gedZ ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE java latest d23bdf5b1b1b 2 years ago 643MB
[root@iZbp16cdvzk4rhl0vn1gedZ ~]# docker load < cc.tar d69483a6face: Loading layer [==================================================>] 209.5MB/209.5MB Loaded image: bb:v1.0
[root@iZbp16cdvzk4rhl0vn1gedZ ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE bb v1.0 3b8d26737bcb 15 minutes ago 202MB java latest d23bdf5b1b1b 2 years ago 643MB