Docker 镜像导入导出

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

Docker 镜像导入导出

青衫解衣   2022-05-28 我要评论

docker save

说明:将指定镜像保存成 tar 归档文件,以tar和tar.gz结尾都行。

语法:

docker save [OPTIONS] IMAGE [IMAGE...]

OPTIONS 说明:

  • -o :输出到的文件。
[root@harbor tmp]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
redis v1 cc6cf492f595 6 hours ago 113MB
busybox latest beae173ccac6 3 months ago 1.24MB
nginx latest 605c77e624dd 3 months ago 141MB
redis latest 7614ae9453d1 3 months ago 113MB
[root@harbor tmp]# docker save -o nginx.tar nginx:latest
[root@harbor tmp]# ls
nginx.tar
[root@harbor tmp]# docker save -o nginx.tar.gz nginx:latest
[root@harbor tmp]# ls
nginx.tar nginx.tar.gz

docker load

说明:导入使用 ​ ​docker save​​ 命令导出的镜像。

语法:

docker load [OPTIONS]

OPTIONS 说明:

  • --input , -i :指定导入的文件,代替 STDIN。
  • --quiet , -q :精简输出信息。

以tar.gz结尾镜像包导入

[root@harbor tmp]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
redis latest 7614ae9453d1 3 months ago 113MB
[root@harbor tmp]# docker load < nginx.tar.gz
e379e8aedd4d: Loading layer [==================================================>] 62MB/62MB
b8d6e692a25e: Loading layer [==================================================>] 3.072kB/3.072kB
f1db227348d0: Loading layer [==================================================>] 4.096kB/4.096kB
32ce5f6a5106: Loading layer [==================================================>] 3.584kB/3.584kB
d874fd2bc83b: Loading layer [==================================================>] 7.168kB/7.168kB
Loaded image: nginx:latest
[root@harbor tmp]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 605c77e624dd 3 months ago 141MB
redis latest 7614ae9453d1 3 months ago 113MB

以tar结尾镜像包导入

[root@harbor tmp]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
redis latest 7614ae9453d1 3 months ago 113MB
[root@harbor tmp]# docker load < nginx.tar
e379e8aedd4d: Loading layer [==================================================>] 62MB/62MB
b8d6e692a25e: Loading layer [==================================================>] 3.072kB/3.072kB
f1db227348d0: Loading layer [==================================================>] 4.096kB/4.096kB
32ce5f6a5106: Loading layer [==================================================>] 3.584kB/3.584kB
d874fd2bc83b: Loading layer [==================================================>] 7.168kB/7.168kB
Loaded image: nginx:latest
[root@harbor tmp]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 605c77e624dd 3 months ago 141MB
redis latest 7614ae9453d1 3 months ago 113MB

Docker export 命令

说明:将指定运行或停止的容器导出为tar包。

语法:

docker export [OPTIONS] CONTAINER

OPTIONS说明:

  • -o :将输入内容写到文件。

使用redis:latest镜像运行一个docker redis容器。

[root@harbor tmp]# docker run -d --name redis redis:latest
00bd9bf582ffdf7dc89793252de9b663ce5b685061bb3652d167924270bed423
[root@harbor tmp]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
00bd9bf582ff redis:latest "docker-entrypoint.s…" 3 seconds ago Up 2 seconds 6379/tcp redis

将运行中的redis容器导出称为redis.tar.gz包。

[root@harbor tmp]# docker export -o redis.tar.gz redis
[root@harbor tmp]# ls
nginx.tar nginx.tar.gz redis.tar.gz

停止redis容器

[root@harbor tmp]# docker stop redis
redis

将已经停止的redis容器导出为redis1.tzr.gz包

[root@harbor tmp]# docker export -o redis1.tar.gz redis
[root@harbor tmp]# ls
nginx.tar nginx.tar.gz redis1.tar.gz redis.tar.gz

Docker import

说明:从 tar包导入内容以docker 镜像。

语法

docker import [OPTIONS] file|URL|- [REPOSITORY[:TAG]]

OPTIONS说明:

  • -c :应用docker 指令创建镜像;
  • -m :提交时的说明文字

您可以指定一个​​URL​​或​​-​​(破折号)直接从​​STDIN​​. ​​URL​​可以指向包含文件系统的存档(.tar、.tar.gz、.tgz、.bzip、.tar.xz 或 .txz)或 Docker 主机上的单个文件。 如果你指定一个存档,Docker 会在相对于​​/​​ (root) 的容器中解压它。如果指定单个文件,则必须指定主机内的完整路径。要从远程位置导入,请指定以or协议​​URI​​开头的 a。​​http://​​​​https://​

[root@harbor tmp]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
redis latest 7614ae9453d1 3 months ago 113MB
[root@harbor tmp]# docker import redis1.tar.gz redis:v1
sha256:07d6e5a00daa386ed5117d7bf7751f74b46f5831aea69036580cd509bb6781e7
[root@harbor tmp]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
redis v1 07d6e5a00daa 2 seconds ago 109MB
redis latest 7614ae9453d1 3 months ago 113MB

通过url导出镜像

docker import https://example.com/exampleimage.tgz

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们