当前位置: 首页 > news >正文

Docker Registry服务器部署配置

为什么80%的码农都做不了架构师?>>>   hot3.png

Docker Registry服务器部署非常简单,只需要合并运行镜像即可,由于Docker Registry服务器整合很多服务,配置的参数非常多,包括:存储,Redis,Auth,日志,中间件,监控,HTTP,通知,健康检查,代理,兼容性

部署Registry服务器

docker run -d -p 5000:5000 --restart=always --name registry \
  -v `pwd`/data:/var/lib/registry \
  registry:2

部署服务器非常简单,只需要一条命令,映射5000端口到容器,restart机制为总是,并分配当前目录下的data目录作为容器卷,存储镜像数据,你可以配置HTTPS方式的访问,如果需要配置TSL请参考Docker官方文档,如果是在局域网内访问这个方式即可满足需求

测试Registry服务

在测试之前必须要理解镜像的命名,理解下面的两条命令

docker pull ubuntu 

这个命令是从Docker官方的hub拉取ubuntu镜像,这是简写的方式,完整的命令是这样的docker pull docker.io/library/ubuntu

docker pull localhost:5000/foo/bar

这个命令是从localhost:5000拉取foo/bar镜像,接下来尝试从Docker Hub拉取镜像并推送到本地的Registry服务器,以Ubuntu为例

从Docker Hub拉取Ubuntu镜像并命名为localhost:5000/ubuntu

docker pull ubuntu && docker tag ubuntu localhost:5000/ubuntu

推送镜像到本地的Registry服务器

docker push localhost:5000/ubuntu

删除宿主机的localhost:5000/ubuntu并拉取Registry服务器的ubuntu镜像

docker rmi -f localhost:5000/ubuntu
docker pull localhost:5000/ubuntu

配置Registry服务器

配置Registry服务器的方式有两种,一种是在运行容器指定环境变量重写配置文件,另一种是直接映射yaml配置文件,建议使用配置文件的方式,这样迁移方便

环境变量重写配置选项

比如重写配置文件存储选项,文件配置如下所示

storage:
  filesystem:
    rootdirectory: /var/lib/registry

那么运行Registery容器时就需要指定环境变量REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY=/somewhere

docker run -d -p 5000:5000 --restart=always --name registry \
  -v `pwd`/data:/var/lib/registry \
  -e  REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY=/somewhere \
  registry:2

覆盖配置文件

可以使用挂载卷的方式覆盖配置,个人建议使用这种方式配置

docker run -d -p 5000:5000 --restart=always --name registry \
             -v `pwd`/config.yml:/etc/docker/registry/config.yml \
             registry:2

挂载当前目录下config.yml覆盖容器的/etc/docker/registry/config.yml文件,下面是整个配置文件,参数非常之多,解释一些常用的

version: 0.1
log: ## 日志选项
  level: debug
  formatter: text
  fields:
    service: registry
    environment: staging
  hooks:
    - type: mail
      disabled: true
      levels:
        - panic
      options:
        smtp:## 邮件通知配置
          addr: mail.example.com:25
          username: mailuser
          password: password
          insecure: true
        from: sender@example.com
        to:
          - errors@example.com
loglevel: debug # 即将弃用: 使用Log替代
storage:##存储选项,
  filesystem: ## 本地文件系统,也可以是云分布式存储,比如微软Azure,亚马逊S3,swift,OSS
    rootdirectory: /var/lib/registry
    maxthreads: 100 ##最大线程数
auth: #用户验证
  silly:
    realm: silly-realm
    service: silly-service
  token:
    realm: token-realm
    service: token-service
    issuer: registry-token-issuer
    rootcertbundle: /root/certs/bundle
  htpasswd:
    realm: basic-realm
    path: /path/to/htpasswd
middleware:##中间件类型有registry,repository,storage三种,每种中间件可以像下面的方式使用
  registry:
    - name: ARegistryMiddleware
      options:
        foo: bar
  storage:
    - name: ARegistryMiddleware
reporting:##监控,可以使用一些在线的监控工具包括bugsnag,newrelic
  newrelic:
    licensekey: newreliclicensekey
    name: newrelicname
    verbose: true
http:## 由Nginx提供的HTTP服务,可以把它理解成配置Nginx
  addr: localhost:5000
  prefix: /my/nested/registry/
  host: https://myregistryaddress.org:5000
  secret: asecretforlocaldevelopment
  relativeurls: false
  tls:
    certificate: /path/to/x509/public
    key: /path/to/x509/private
    clientcas:
      - /path/to/ca.pem
      - /path/to/another/ca.pem
    letsencrypt:
      cachefile: /path/to/cache-file
      email: emailused@letsencrypt.com
  debug:
    addr: localhost:5001
  headers:
    X-Content-Type-Options: [nosniff]
notifications:## 事件通知,当Registry服务器发生拉取,推送等时发送事件到endpoints
  endpoints:
    - name: alistener
      disabled: false
      url: https://my.listener.com/event
      headers: <http.Header>
      timeout: 500
      threshold: 5
      backoff: 1000
redis:##这个用过的都懂
  addr: localhost:6379
  password: asecret
  db: 0
  dialtimeout: 10ms
  readtimeout: 10ms
  writetimeout: 10ms
  pool:
    maxidle: 16
    maxactive: 64
    idletimeout: 300s
health:## 健康检查包括存储驱动,file,http服务,tcp的可用性检查
  storagedriver:
    enabled: true
    interval: 10s
    threshold: 3
  file:
    - file: /path/to/checked/file
      interval: 10s
  http:
    - uri: http://server.to.check/must/return/200
      headers:
        Authorization: [Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==]
      statuscode: 200
      timeout: 3s
      interval: 10s
      threshold: 3
  tcp:
    - addr: redis-server.domain.com:6379
      timeout: 3s
      interval: 10s
      threshold: 3
proxy:## 可以镜像Docker Hub的仓库
  remoteurl: https://registry-1.docker.io
  username: [username]
  password: [password]
compatibility: 
  schema1:
    signingkeyfile: /etc/registry/key.json

配置文件好长,请根据需求配置

转载于:https://my.oschina.net/freax/blog/825925

相关文章:

  • C++类、继承、多态、虚函数
  • ZOJ 3329 One Person Game
  • pyinstall tkinter image
  • CSS快速入门
  • 强力优化Rancher k8s中国区的使用体验
  • Windows 8 Platform (三) Windows 8 Developer Preview
  • 关于责任和业务(r11笔记第60天)
  • 如何测试网页登录
  • C#分部类型解析
  • 博为峰Java技术文章 ——JavaSE Swing JTabbedPane选项卡面板II
  • JS 设置盒子div 跳转
  • 数组操作函数总结
  • 在Unity(C#)下实现Lazy Theta*寻路
  • 双显卡笔记本安装CUDA+theano、tensorflow环境
  • Zabbix3.x 服务安装、配置及常见问题处理
  • 【node学习】协程
  • ESLint简单操作
  • exif信息对照
  • Logstash 参考指南(目录)
  • Map集合、散列表、红黑树介绍
  • Markdown 语法简单说明
  • Perseus-BERT——业内性能极致优化的BERT训练方案
  • PHP那些事儿
  • spark本地环境的搭建到运行第一个spark程序
  • Transformer-XL: Unleashing the Potential of Attention Models
  • zookeeper系列(七)实战分布式命名服务
  • 程序员最讨厌的9句话,你可有补充?
  • 经典排序算法及其 Java 实现
  • 力扣(LeetCode)357
  • 前端技术周刊 2019-02-11 Serverless
  • 使用Envoy 作Sidecar Proxy的微服务模式-4.Prometheus的指标收集
  • 探索 JS 中的模块化
  • 腾讯优测优分享 | Android碎片化问题小结——关于闪光灯的那些事儿
  • 通过npm或yarn自动生成vue组件
  • 文本多行溢出显示...之最后一行不到行尾的解决
  • #Js篇:单线程模式同步任务异步任务任务队列事件循环setTimeout() setInterval()
  • (poj1.3.2)1791(构造法模拟)
  • (补)B+树一些思想
  • (翻译)terry crowley: 写给程序员
  • (附源码)ssm高校社团管理系统 毕业设计 234162
  • (力扣题库)跳跃游戏II(c++)
  • (每日持续更新)信息系统项目管理(第四版)(高级项目管理)考试重点整理 第13章 项目资源管理(七)
  • (七)MySQL是如何将LRU链表的使用性能优化到极致的?
  • (一)【Jmeter】JDK及Jmeter的安装部署及简单配置
  • (转)母版页和相对路径
  • (转)为C# Windows服务添加安装程序
  • .Family_物联网
  • .NET Standard 支持的 .NET Framework 和 .NET Core
  • ::
  • @NestedConfigurationProperty 注解用法
  • [2018-01-08] Python强化周的第一天
  • [AIGC codze] Kafka 的 rebalance 机制
  • [ARM]ldr 和 adr 伪指令的区别
  • [BUUCTF NewStarCTF 2023 公开赛道] week3 crypto/pwn
  • [BZOJ 4598][Sdoi2016]模式字符串