Docker使用save和load进行保存镜像到本地和从本地加载镜像

我会带着你远行 2023-01-20 09:38 43阅读 0赞

一 保存镜像

  1. [root@localhost mydocker]# docker save --help
  2. Usage: docker save [OPTIONS] IMAGE [IMAGE...]
  3. Save one or more images to a tar archive (streamed to STDOUT by default)
  4. Options:
  5. -o, --output string Write to a file, instead of STDOUT

-o 指定保存镜像的位置

保存镜像时候要用镜像名称:标签,不要用镜像ID,否则导入默认镜像名称和版本为null。

保存镜像redis到 /mydocker/images/redis.tar

  1. [root@localhost mydocker]# docker images
  2. REPOSITORY TAG IMAGE ID CREATED SIZE
  3. redis latest ccee4cdf984f 8 days ago 105MB
  4. [root@localhost mydocker]# ls
  5. jdk.tar.gz tomcat9 tomcat.tar.gz
  6. [root@localhost mydocker]# mkdir images
  7. [root@localhost mydocker]# cd images/
  8. [root@localhost images]# ls
  9. [root@localhost images]# docker save -o /mydocker/images/redis.tar redis
  10. [root@localhost images]# ls
  11. redis.tar

二 加载镜像

  1. [root@localhost mydocker]# docker load --help
  2. Usage: docker load [OPTIONS]
  3. Load an image from a tar archive or STDIN
  4. Options:
  5. -i, --input string Read from tar archive file, instead of STDIN
  6. -q, --quiet Suppress the load output

-i 指定加载的镜像

  1. [root@localhost images]# docker rmi redis
  2. Untagged: redis:latest
  3. Untagged: redis@sha256:6cddb3822e19f09a6a369c35680562ddd2e44bd3bfd6fe25ec6456c42f45728b
  4. Deleted: sha256:ccee4cdf984f11952441cbab30146dae792c8d9fb668e762c78a49e7db858082
  5. Deleted: sha256:a4f3d68d06ee9aec1862695818528930f0e889f5c892da8be4c06759dc2e8f86
  6. Deleted: sha256:02c22c39334cefb22054330d3be804a3046286d7f0a47d83f5f25be13f4e635e
  7. Deleted: sha256:2d01997f1c500789fc369f5440ea810257641af6fbb1d4eaeb9558d94ea8879d
  8. Deleted: sha256:f448a5cc1367794bb2f15d887438c8b43f2324ee3523f5d95c15997685cc816d
  9. Deleted: sha256:e481db33c0c73ee7de5ecda57c21fcfb7eeeff7d22fcc4ad0166b0bf64a63a32
  10. [root@localhost images]# docker images
  11. REPOSITORY TAG IMAGE ID CREATED SIZE
  12. [root@localhost images]# docker load -i /mydocker/images/redis.tar
  13. 89ce1a07a7e4: Loading layer [==================================================>] 338.4kB/338.4kB
  14. 9eef6e3cc293: Loading layer [==================================================>] 4.194MB/4.194MB
  15. ee748697d275: Loading layer [==================================================>] 31.7MB/31.7MB
  16. f1f7964d40af: Loading layer [==================================================>] 2.048kB/2.048kB
  17. 3d9fda8ff875: Loading layer [==================================================>] 3.584kB/3.584kB
  18. Loaded image: redis:latest
  19. [root@localhost images]# docker image
  20. Usage: docker image COMMAND
  21. Manage images
  22. Commands:
  23. build Build an image from a Dockerfile
  24. history Show the history of an image
  25. import Import the contents from a tarball to create a filesystem image
  26. inspect Display detailed information on one or more images
  27. load Load an image from a tar archive or STDIN
  28. ls List images
  29. prune Remove unused images
  30. pull Pull an image or a repository from a registry
  31. push Push an image or a repository to a registry
  32. rm Remove one or more images
  33. save Save one or more images to a tar archive (streamed to STDOUT by default)
  34. tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
  35. Run 'docker image COMMAND --help' for more information on a command.
  36. [root@localhost images]# docker images
  37. REPOSITORY TAG IMAGE ID CREATED SIZE
  38. redis latest ccee4cdf984f 8 days ago 105MB

发表评论

表情:
评论列表 (有 0 条评论,43人围观)

还没有评论,来说两句吧...

相关阅读