IT评测·应用市场-qidao123.com

标题: 关于 Docker Registry (镜像堆栈) [打印本页]

作者: 鼠扑    时间: 2024-7-18 03:44
标题: 关于 Docker Registry (镜像堆栈)
什么是镜像堆栈

概念

镜像堆栈(Docker Registry)负责存储、管理和分发镜像,并提供了登录认证本领,创建了堆栈的索引。
镜像堆栈管理多个 Repository,Repository 通过定名来区分。每个 Repository 包含一个或多个镜像,镜像通过镜像名称和标签(Tag)来区分(也就是每个镜像的每一个小版本)。
   一个容器镜像又包含 元数据 和 blob。
  元数据就是由 dockerfile 构建出来的描述文件,重要记载了一个容器镜像有多少层,每一层里有什么内容。
  blob 中存储的就是真正的可实验文件,也是真正占有空间的东西。
  


镜像堆栈分类

按是否对外开放划分:
按供应商和面向群体划分:
镜像堆栈工作机制

镜像堆栈利用流程


镜像堆栈如何在实际研发中利用

首先要知道,一个项目或系统,从开始研发到上线利用的过程中,要颠末几个差别的情况。

针对差别的阶段要有差别的情况,才能得到想要的结果,以是也就需要差别的镜像来满意差别阶段对于情况的差别需求。
Docker Registry 中的镜像通常由开发人员制作,然后推送到公有或私有的 Registry 上生存,供其他人员利用,例如摆设到生产情况。

镜像堆栈的拉取机制

启动容器时,docker daemon 会试图从本地获取相干的镜像。本地镜像不存在时,其将从 Registry 中下载该镜像并生存到本地。
搭建 nginx 服务

相识 web 服务器和 Nginx

   Web 服务器,一般是指“网站服务器”,是指驻留于互联网上某种类型计算机的程序。Web 服务器可以向 Web 欣赏器等客户端提供文档,也可以防止网站文件,让全世界欣赏,更可以放置数据文件,让全世界下载。
  Nginx 作为 web 服务器可以向各种欣赏器等客户端提供欣赏服务,比如通过手机、电脑、平板可以访问百度来实现对 web 服务器的访问。
正向署理

由于防火墙的缘故原由,我们并不能直接访问外网,可以借助 VPN 来实现,这就是一个正向署理的例子。
正向署理“署理”的是客户端,而客户端是知道目标的,目标是不知道客户端是通过 VPN 访问的。

反向署理

当我们在外网访问百度的时间,实在会进行一个转发,署理到内网,这就是所谓的反向署理。
也就是说,反向署理“署理”的是服务器端,而且这个过程对于客户端而言是透明的。

开始搭建 Nginx

原来按理来说,应该先介绍搭建过程中涉及到的各种命令,但是,我懒得写了...读者如果遇到了自己不熟悉的命令,请先跳转百度一下!
先找到一个合适的 nginx
  1. root@hcss-ecs-3f38:~# docker search nginx
  2. NAME                               DESCRIPTION                                     STARS     OFFICIAL
  3. nginx                              Official build of Nginx.                        19996     [OK]
  4. unit                               Official build of NGINX Unit: Universal Web …   32        [OK]
  5. nginx/nginx-ingress                NGINX and  NGINX Plus Ingress Controllers fo…   92        
  6. nginxinc/nginx-unprivileged        Unprivileged NGINX Dockerfiles                  154      
  7. nginx/nginx-prometheus-exporter    NGINX Prometheus Exporter for NGINX and NGIN…   42        
  8. nginx/nginx-ingress-operator       NGINX Ingress Operator for NGINX and NGINX P…   2         
  9. nginx/unit                         This repository is retired, use the Docker o…   63        
  10. nginxinc/nginx-s3-gateway          Authenticating and caching gateway based on …   6         
  11. nginx/nginx-quic-qns               NGINX QUIC interop                              1         
  12. nginxinc/amplify-agent             NGINX Amplify Agent docker repository           1         
  13. nginxinc/ingress-demo              Ingress Demo                                    4         
  14. nginxproxy/nginx-proxy             Automated nginx proxy for Docker containers …   142      
  15. nginx/unit-preview                 Unit preview features                           0         
  16. bitnami/nginx                      Bitnami container image for NGINX               192      
  17. nginxproxy/acme-companion          Automated ACME SSL certificate generation fo…   135      
  18. ubuntu/nginx                       Nginx, a high-performance reverse proxy & we…   114      
  19. nginxproxy/docker-gen              Generate files from docker container meta-da…   17        
  20. kasmweb/nginx                      An Nginx image based off nginx:alpine and in…   8         
  21. bitnami/nginx-ingress-controller   Bitnami container image for NGINX Ingress Co…   34        
  22. nginxinc/ngx-rust-tool                                                             0         
  23. nginxinc/mra_python_base                                                           0         
  24. nginxinc/mra-fakes3                                                                0         
  25. bitnami/nginx-exporter             Bitnami container image for NGINX Exporter      5         
  26. rancher/nginx                                                                      2         
  27. root@hcss-ecs-3f38:~#
复制代码
但是这样命令行的方式查找,不会表现详细的信息,照旧发起到官网去查。(更发起利用已经认证过的 nginx)
找到你喜欢的那个镜像,然后拉取:
  1. root@hcss-ecs-3f38:~# docker pull nginx:1.23.3
  2. 1.23.3: Pulling from library/nginx
  3. 3f9582a2cbe7: Pull complete  
  4. 9a8c6f286718: Pull complete  
  5. e81b85700bc2: Pull complete  
  6. 73ae4d451120: Pull complete  
  7. 6058e3569a68: Pull complete  
  8. 3a1b8f201356: Pull complete  
  9. Digest:  
  10. sha256:aa0afebbb3cfa473099a62c4b32e9b3fb73ed23f2a75a65ce1d4b4f55a5
  11. c2ef2
  12. Status: Downloaded newer image for nginx:1.23.3
  13. docker.io/library/nginx:1.23.3
复制代码
然后查看镜像是否拉取成功:
  1. root@hcss-ecs-3f38:~# docker images
  2. REPOSITORY TAG IMAGE ID CREATED SIZE
  3. nginx 1.23.3 904b8cb13b93 8 days ago 142MB
  4. hello-world latest feb5d9fea6a5 17 months ago 13.3kB
复制代码
然后运行镜像:
  1. docker run --name nginx1 --rm -it -p 80:80 nginx:1.23.3 bash
复制代码
然后查看一下,在容器的 shell 中,实验 cat /etc/"release" 查看操作系统照旧不是 Ubuntu。
之后,启动 nginx:
  1. root@hcss-ecs-3f38:~# nginx
  2. 2023/03/10 11:22:05 [notice] 7#7: using the "epoll" event method
  3. 2023/03/10 11:22:05 [notice] 7#7: nginx/1.23.3
  4. 2023/03/10 11:22:05 [notice] 7#7: built by gcc 10.2.1 20210110  
  5. (Debian 10.2.1-6)  
  6. 2023/03/10 11:22:05 [notice] 7#7: OS: Linux 5.4.0-100-generic
  7. 2023/03/10 11:22:05 [notice] 7#7: getrlimit(RLIMIT_NOFILE):  
  8. 1048576:1048576
  9. root@5f377aec47ce:/# 2023/03/10 11:22:05 [notice] 8#8: start  
  10. worker processes
  11. 2023/03/10 11:22:05 [notice] 8#8: start worker process 9
  12. 172.17.0.1 - - [10/Mar/2023:11:22:15 +0000] "GET / HTTP/1.1" 200  
  13. 615 "-" "curl/7.68.0" "-"
复制代码
然后保持这个 shell 不退出,打开另一个 shell 窗口实验 curl 命令,可以看到 nginx 的接待信息返回:
  1. Shell
  2. root@hcss-ecs-3f38:~# curl 127.0.0.1
  3. <!DOCTYPE html>
  4. <html>
  5. <head>
  6. <title>Welcome to nginx!</title>
  7. <style>
  8. html { color-scheme: light dark; }
  9. body { width: 35em; margin: 0 auto;
  10. font-family: Tahoma, Verdana, Arial, sans-serif; }
  11. </style>
  12. </head>
  13. <body>
  14. <h1>Welcome to nginx!</h1>
  15. <p>If you see this page, the nginx web server is successfully  
  16. installed and
  17. working. Further configuration is required.</p>
  18. <p>For online documentation and support please refer to
  19. <a href="http://nginx.org/">nginx.org</a>.<br/>
  20. Commercial support is available at
  21. <a href="http://nginx.com/">nginx.com</a>.</p>
  22. <p><em>Thank you for using nginx.</em></p>
  23. </body>
  24. </html>
复制代码
如果你的服务器的 80 端口外部能访问,则可以用欣赏器看到 nginx 的接待页面。
注意云厂商一般都屏蔽了 80 端口,需要联系客服开通。
之后,shell 退出观察再 curl 发现已经 ping 不通了,说明 nginx 是容器里的,而不是服务器里的。
  1. root@hcss-ecs-3f38:~# curl 127.0.0.1
  2. curl: (7) Failed to connect to 127.0.0.1 port 80: Connection  
  3. refused
复制代码


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 IT评测·应用市场-qidao123.com (https://dis.qidao123.com/) Powered by Discuz! X3.4