背景说明

镜像是一种轻量级的,可执行的独立软件包,用来打包软件运行时环境和基于运行时环境开发的软件,它包含运行某个软件所需的所有内容,包括精简操作系统、代码、运行时所需要的库、环境变量和配置文件。

解决方案

层次结构

  1. [root@vm1 ~]# docker history nginx
  2. IMAGE CREATED CREATED BY SIZE COMMENT
  3. 605c77e624dd 3 months ago /bin/sh -c #(nop) CMD ["nginx" "-g" "daemon… 0B
  4. <missing> 3 months ago /bin/sh -c #(nop) STOPSIGNAL SIGQUIT 0B
  5. <missing> 3 months ago /bin/sh -c #(nop) EXPOSE 80 0B
  6. <missing> 3 months ago /bin/sh -c #(nop) ENTRYPOINT ["/docker-entr… 0B
  7. <missing> 3 months ago /bin/sh -c #(nop) COPY file:09a214a3e07c919a… 4.61kB
  8. <missing> 3 months ago /bin/sh -c #(nop) COPY file:0fd5fca330dcd6a7… 1.04kB
  9. <missing> 3 months ago /bin/sh -c #(nop) COPY file:0b866ff3fc1ef5b0… 1.96kB
  10. <missing> 3 months ago /bin/sh -c #(nop) COPY file:65504f71f5855ca0… 1.2kB
  11. <missing> 3 months ago /bin/sh -c set -x && addgroup --system -… 61.1MB
  12. <missing> 3 months ago /bin/sh -c #(nop) ENV PKG_RELEASE=1~bullseye 0B
  13. <missing> 3 months ago /bin/sh -c #(nop) ENV NJS_VERSION=0.7.1 0B
  14. <missing> 3 months ago /bin/sh -c #(nop) ENV NGINX_VERSION=1.21.5 0B
  15. <missing> 3 months ago /bin/sh -c #(nop) LABEL maintainer=NGINX Do… 0B
  16. <missing> 3 months ago /bin/sh -c #(nop) CMD ["bash"] 0B
  17. <missing> 3 months ago /bin/sh -c #(nop) ADD file:09675d11695f65c55… 80.4MB
  18. [root@vm1 ~]#

镜像导出

  1. [root@vm1 bin]# docker save -o nginx.tar nginx:latest

镜像导出时建议使用镜像的名称不要使用镜像ID,因为使用镜像ID进行导出二次导入后会缺失镜像tag标签 多镜像导出docker save nginx:latest mysql:latest > file.tar

镜像导入

  1. [root@vm1 bin]# docker load -i nginx.tar

镜像删除

docker -rmi

docker rm 容器标识 表示删除容器,i标识image用来删除镜像

镜像查看

IMAGE ID完整是128位,一般情况下使用前4位表示即可。

  1. [root@vm1 bin]# docker images
  2. REPOSITORY TAG IMAGE ID CREATED SIZE
  3. golang latest 276895edf967 3 months ago 941MB
  4. haproxy latest 575a5788d81a 3 months ago 101MB
  5. franela/dind latest b1018f4f6189 16 months ago 698MB
  6. jekyll/jekyll 3 f68afd75b4c4 2 years ago 457MB
  7. franela/play-with-docker latest 2a4b53926250 4 years ago 21.8MB
  8. jekyll/jekyll 3.2 2b863c097a4c 4 years ago 340MB
  9. [root@vm1 bin]# docker images --no-trunc
  10. REPOSITORY TAG IMAGE ID CREATED SIZE
  11. golang latest sha256:276895edf9673267f47528e8a99401f2d2947f6c9c00490f773d5ed8f559bef2 3 months ago 941MB
  12. haproxy latest sha256:575a5788d81a84fe411fed2c6c2aaca938b5a36e41fdee042af42373888961e2 3 months ago 101MB
  13. franela/dind latest sha256:b1018f4f61893bb1795e247d7ec24144d88a87aca3ffa6802304ccfc8e100dce 16 months ago 698MB
  14. jekyll/jekyll 3 sha256:f68afd75b4c4013a78b9ab3e258a0f0b284c2394fd13ebfd0bc27b40df3da200 2 years ago 457MB
  15. franela/play-with-docker latest sha256:2a4b539262502d34063f3ffc415b511bba79a246968d71159f2c303e1773f0cd 4 years ago 21.8MB
  16. jekyll/jekyll 3.2 sha256:2b863c097a4c614aa82cf0f173ee244b9b9ae0a7373e0f3123c37f73ff4868fe 4 years ago 340MB
  17. [root@vm1 bin]#

镜像仓库

网易数帆

https://console.163yun.com/
image.png
https://c.163yun.com/dashboard
image.png
点击右侧的镜像中心:https://c.163yun.com/hub#/home
image.png

规则命名

仓库地址/用户名称/镜像名称:版本号
docker pull nginx <==>docker pull docker.io/library/nginx:latest

镜像字段

OFFICIAL:表示是不是官方提供的镜像
AUTOMATED:表示是不有前台进程,没有前台进程的镜像用来当做基础镜像来做子镜像,没有前台进程的镜像运行完即终止。

  1. [root@vm1 bin]# docker search nginx

image.png