目录
准备环境:
Ubuntu 20.04
CentOS Stream 8
Docker 20.10.13
1.save和load
1.0在ubuntu系统上下载一个ubuntu镜像
#因为我下载过了,所以会显示如上
1.1save保存镜像
docker save [OPTIONS] IMAGE [IMAGE...]
Save one or more images to a tar archive (streamed to STDOUT by default)
Options:
-o, --output string Write to a file, instead of STDOUT #输出为一个文件sc-ubuntu.tar为目标文件,ubuntu为源镜像名(image:tags)
1.2传输sc-ubuntu.tar
scp sc-ubuntu.tar root@123.56.3.24:/root
1.3load导入镜像
docker load [OPTIONS]Load an image from a tar archive or STDIN
Options:
-i, --input string Read from tar archive file, instead of STDIN #从一个rat文件中读入
-q, --quiet Suppress the load outputsc-ubuntu.tar为要读取的tar文件
2.export和import
2.0在ubuntu系统上下载一个centos镜像
2.1使用centos镜像创建一个容器
#因为export是从容器(container)中导出,所以需要创建一个容器。
#运行或停止的容器都可以export出
2.2export导出镜像
docker export [OPTIONS] CONTAINER
Export a container's filesystem as a tar archive
Options:
-o, --output string Write to a file, instead of STDOUT #保存到文件
2.3传输文件
scp sc-centos.tar root@123.56.3.24:/root
2.4import导入文件
docker import [OPTIONS] file|URL|- [REPOSITORY[:TAG]]
Import the contents from a tarball to create a filesystem image
Options:
-c, --change list Apply Dockerfile instruction to the created image
-m, --message string Set commit message for imported image
--platform string Set platform if server is multi-platform capable#sc-centos.tar为要读取的文件 centos:7为命名镜像名和版本号
3.两组命令的区别
save和load是从镜像(images)中导入导出.
export和import是从容器(container)中导入导出.
#两组不能搭配使用!