011.Docker仓库管理
2019-01-15 02:25:57来源:博客园 阅读 ()
一 Docker仓库介绍
二 Docker私有仓库构建
2.1 私有仓库构建形式
三 registry构建:无认证部署
3.1 下载registry
1 root@docker01:~# wget https://github.com/mkuchin/docker-registry-web/releases/download/v0.1.2/examples.tar.gz 2 root@docker01:~# tar -zxvf examples.tar.gz 3 root@docker01:~# mv examples compose_registry
3.2 docker-compose构建
1 root@docker01:~# mkdir -p /registry/db 2 root@docker01:~# mkdir -p /registry/images 3 root@docker01:~# cd compose_registry/auth-disabled/ 4 root@docker01:~/compose_registry/auth-disabled# vi conf/registry/config.yml 5 version: 0.1 6 storage: 7 filesystem: 8 rootdirectory: /registry #指定registry工作目录 9 delete: 10 enabled: true #开启删除功能 11 http: 12 addr: 0.0.0.0:5000 13 notifications: 14 endpoints: 15 - name: listener 16 url: http://registry-web:8080/api/notification 17 timeout: 500ms 18 threshold: 5 19 backoff: 1s 20 root@docker01:~/compose_registry/auth-disabled# vi conf/registry-web/config.yml 21 registry: 22 url: http://registry:5000/v2 23 name: 172.24.8.111:5000 24 readonly: false 25 auth: 26 enabled: false #关闭相关认证 27 root@docker01:~/compose_registry/auth-disabled# vi docker-compose.yml 28 version: '2' 29 services: 30 registry-web: 31 image: hyper/docker-registry-web:latest 32 ports: 33 - 8080:8080 34 volumes: 35 - ./conf/registry-web:/conf:ro 36 - /registry/db:/data #修改db保存目录 37 networks: 38 - registry-net 39 depends_on: 40 - registry 41 registry: 42 image: registry:2.4.1 43 ports: 44 - 5000:5000 45 volumes: 46 - /registry/images:/registry #修改镜像保存路径 47 - ./conf/registry:/etc/docker/registry:ro 48 networks: 49 - registry-net 50 networks: 51 registry-net: 52 # driver: default
3.3 docker-compose启动容器
1 root@docker01:~/compose_registry/auth-disabled# docker-compose up -d
3.4 客户端测试
1 root@docker02:~# vi /etc/docker/daemon.json 2 { 3 "insecure-registries": ["172.24.8.111:5000"] 4 } 5 root@docker02:~# docker pull hello-world #pull测试镜像 6 root@docker02:~# docker tag hello-world:latest 172.24.8.111:5000/registry/hello-world:xhy #修改对应的tag 7 root@docker02:~# docker push 172.24.8.111:5000/registry/hello-world
四 registry构建:开启认证部署
4.1 下载registry
4.2 docker-compose构建
1 root@docker01:~# mkdir -p /registry/db 2 root@docker01:~# mkdir -p /registry/images 3 root@docker01:~# cd compose_registry/auth-enabled/ 4 root@docker01:~/compose_registry/auth-enabled# vi conf/registry/config.yml 5 version: 0.1 6 storage: 7 filesystem: 8 rootdirectory: /registry 9 delete: 10 enabled: true #开启删除功能 11 http: 12 addr: 0.0.0.0:5000 13 auth: 14 token: 15 realm: http://172.24.8.111:8080/api/auth 16 service: 172.24.8.111:5000 17 issuer: test 18 rootcertbundle: /etc/docker/registry/auth.cert #配置cert路径 19 log: 20 level: info 21 22 notifications: 23 endpoints: 24 - name: listener 25 url: http://registry-web:8080/api/notification 26 timeout: 500ms 27 threshold: 5 28 backoff: 1s 29 root@docker01:~/compose_registry/auth-disabled# vi conf/registry-web/config.yml 30 registry: 31 url: http://registry:5000/v2 32 name: 172.24.8.111:5000 33 readonly: false 34 auth: 35 enabled: true 36 key: /conf/auth.key #指定key的路径 37 issuer: test 38 root@docker01:~/compose_registry/auth-disabled# vi docker-compose.yml 39 version: '2' 40 services: 41 registry-web: 42 image: hyper/docker-registry-web:latest 43 ports: 44 - 8080:8080 45 volumes: 46 - ./conf/registry-web:/conf:ro 47 - /registry/db:/data 48 networks: 49 - registry-net 50 depends_on: 51 - registry 52 registry: 53 image: registry:2.4.1 54 ports: 55 - 5000:5000 56 volumes: 57 - ./conf/registry:/etc/docker/registry:ro 58 - /registry/images:/registry 59 networks: 60 - registry-net 61 networks: 62 registry-net: 63 # driver: default
4.3 生成自签名证书
1 root@docker01:~/compose_registry/nginx-auth-enabled# ./generate-keys.sh
4.4 docker-compose启动容器
1 root@docker01:~/compose_registry/nginx-auth-enabled# docker-compose up -d
4.5 客户端测试
1 root@docker02:~# vi /etc/docker/daemon.json 2 { 3 "insecure-registries": ["172.24.8.111:5000"] 4 } 5 root@docker02:~# docker pull hello-world #pull测试镜像 6 root@docker02:~# docker tag hello-world:latest 172.24.8.111:5000/registry/hello-world:xhy #修改对应的tag
1 root@docker02:~# docker login 172.24.8.111:5000 #输入默认admin/admin登录 2 root@docker02:~# docker push 172.24.8.111:5000/registry/hello-world
五 registry构建:http形式Harbor
5.1 Harbor介绍
- UI: 作为Registry Webhook, 以图像用户界面的方式辅助用户管理镜像。
- WebHook:是在registry中配置的一种机制,当registry中镜像发生改变时,就可以通知到Harbor的webhook endpoint。Harbor使用webhook来更新日志、初始化同步job等。
- Token service:会根据该用户在一个工程中的角色,为每一次的push/pull请求分配对应的token。假如相应的请求并没有包含token的话,registry会将该请求重定向到token service。
5.2 容器组件介绍
- ui:harbor的核心服务。
- log:运行着rsyslog的容器,进行日志收集。
- mysql:由官方mysql镜像构成的数据库容器。
- nginx:使用Nginx做反向代理。
- registry:官方的Docker registry。
- adminserver:harbor的配置数据管理器。
- jobservice:Harbor的任务管理服务。
- redis:用于存储session。
5.3 下载harbor安装文件
1 root@docker01:~# wget https://storage.googleapis.com/harbor-releases/harbor-offline-installer-v1.5.4.tgz 2 root@docker01:~# tar xvf harbor-offline-installer-v1.5.4.tgz
5.4 编辑harbor.cfg
1 root@docker01:~# mkdir /data #harbor默认相关volume挂载目录 2 root@docker01:~# cd harbor/ 3 root@docker01:~/harbor# vi harbor.cfg 4 hostname = reg.itzgr.com # harbor的访问地址
5.5 安装harbor
1 root@docker01:~/harbor# ./install.sh
1 empty_subj = "/C=/ST=/L=/O=/CN=/"
1 empty_subj = "/C=US/ST=California/L=Palo Alto/O=VMware, Inc./OU=Harbor/CN=notarysigner"
5.6 确认验证
1 root@docker01:~# cd harbor 2 root@docker01:~/harbor# docker-compose ps
1 172.24.8.111 reg.itzgr.com
六 registry构建:https形式Harbor
6.1 下载harbor安装文件
6.2 自建证书
1 root@docker01:~# localdomain=reg.itzgr.com 2 root@docker01:~# openssl req \ 3 -newkey rsa:4096 -nodes -sha256 -keyout ca.key \ 4 -x509 -days 365 -out ca.crt #创建CA证书 5 Country Name (2 letter code) [AU]:CN #国家 6 State or Province Name (full name) [Some-State]:ZheJiang #州或省 7 Locality Name (eg, city) []:WenZhou #城市 8 Organization Name (eg, company) [Internet Widgits Pty Ltd]:harbor #机构 9 Organizational Unit Name (eg, section) []:harbor #组织 10 Common Name (e.g. server FQDN or YOUR name) []:reg.itzgr.com #访问域名 11 Email Address []:xhy@itzgr.com #邮箱 12 13 root@docker01:~# openssl req \ 14 -newkey rsa:4096 -nodes -sha256 -keyout $localdomain.key \ 15 -out $localdomain.csr #生成证书签名请求 16 Country Name (2 letter code) [AU]:CN 17 State or Province Name (full name) [Some-State]:ZheJiang 18 Locality Name (eg, city) []:WenZhou 19 Organization Name (eg, company) [Internet Widgits Pty Ltd]:harbor 20 Organizational Unit Name (eg, section) []:harbor 21 Common Name (e.g. server FQDN or YOUR name) []:reg.itzgr.com 22 Email Address []:xhy@itzgr.com 23 A challenge password []:x7374521* 24 An optional company name []:reg.itzgr.com 25 26 root@docker01:~# openssl x509 -req -days 365 -in $localdomain.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out $localdomain.crt 27 root@docker01:~# mkdir /root/cert/ 28 root@docker01:~# cp $localdomain.crt $localdomain.key /root/cert/
6.2 编辑harbor.cfg
1 root@docker01:~# cd harbor/ 2 root@docker01:~/harbor# vi harbor.cfg 3 hostname = reg.itzgr.com 4 ui_url_protocol = https 5 ssl_cert = /root/cert/reg.itzgr.com.crt 6 ssl_cert_key = /root/cert/reg.itzgr.com.key
6.3 安装harbor
1 root@docker01:~/harbor# ./prepare 2 root@docker01:~/harbor# ./install.sh
1 empty_subj = "/C=/ST=/L=/O=/CN=/"
1 empty_subj = "/C=US/ST=California/L=Palo Alto/O=VMware, Inc./OU=Harbor/CN=notarysigner"
1 root@docker01:~# cd harbor 2 root@docker01:~/harbor# docker-compose ps
1 172.24.8.111 reg.itzgr.com
6.5 docker 客户端测试
1 root@docker02:~# vi /etc/hosts 2 172.24.8.111 reg.itzgr.com 3 root@docker02:~# mkdir -p /etc/docker/certs.d/reg.itzgr.com 4 root@docker01:~# scp ca.crt root@172.24.8.112:/etc/docker/certs.d/reg.itzgr.com/
1 root@docker02:~# vi /etc/docker/daemon.json 2 { 3 "insecure-registries": ["https://reg.itzgr.com"] 4 }
1 root@docker02:~# docker login reg.itzgr.com #登录registry 2 Username: admin 3 Password:
1 root@docker02:~# docker pull hello-world 2 root@docker02:~# docker tag hello-world:latest reg.itzgr.com/library/hello-world:xhy 3 root@docker02:~# docker push reg.itzgr.com/library/hello-world:xhy
原文链接:https://www.cnblogs.com/itzgr/p/10177299.html
如有疑问请与原作者联系
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- 运行 docker .... 命令报错 2020-06-10
- 容器技术之Docker私有镜像仓库harbor 2020-06-08
- 容器技术之Docker私有镜像仓库docker-distribution 2020-06-07
- 容器技术之Dockerfile(二) 2020-06-04
- 容器云技术 2020-06-02
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash