美文网首页
6. docker私有registry

6. docker私有registry

作者: epiiplus1equal0 | 来源:发表于2019-09-25 22:54 被阅读0次

docker私有registry

本文基于马哥的docker和k8s视频总结, 在此致谢马哥.

registry分类.png

docker-distribution: Docker toolset to pack, ship, store, and deliver content

此包用于快速创建私有registry

registry: dockerhub上有此镜像, 协助用户托管镜像

docker-registry: 软件包, 由docker-distribution提供

使用docker-registry创建私有registory

基础环境如下:

  • node1: docker image client
  • node2: docker image server, 在这台上安装docker-distribution用作私有registry
yum -y install docker-distribution
rpm -ql docker-distribution
/etc/docker-distribution/registry/config.yml # 主配置文件
/usr/bin/registry
/usr/lib/systemd/system/docker-distribution.service # 服务!
/var/lib/registry # 镜像的存放位置
  • 主配置文件内容:
version: 0.1
log:
  fields:
    service: registry
storage:
    cache:
        layerinfo: inmemory # 缓存在内存中
    filesystem:
        rootdirectory: /var/lib/registry # 这里指定了镜像文件的位置
http:
    addr: :5000 # 本机所有地址的5000端口
# node2上启动docker-distribution服务
systemctl start docker-distribution

# node1上先给镜像打符合格式的标签
docker image tag tianjunchang/nginx:v0.4 node2:5000/nginx:v0.4
# 然后推送至node2的仓库中
docker image push node2:5000/nginx:v0.4 
# 推送过程中会有如下报错, 因为docker默认使用https, 
# 而docker-distribution使用的是http
The push refers to repository [node2:5000/nginx]
Get https://node2:5000/v2/: http: server gave HTTP response to HTTPS client

# 因此需要在node1上作如下修改, 使node1上的docker接受使用非安全的registry:
vi /etc/docker/daemon.json
{
    "registry-mirrors": ["https://p2aci6x1.mirror.aliyuncs.com", "https://registry.docker-cn.com"],
    "insecure-registries": ["node2:5000"] # 添加这项内容, 
                                          # 指定私有registry的ip和port, 
                                          # 有多个时用逗号隔开,
                                          # registry_fqdn:port
}
# 修改完了需要重启docker服务
systemctl restart docker
docker image push node2:5000/nginx:v0.4 # 此时推送成功
ls /var/lib/registry/docker/registry/v2/repositories/
nginx # 可以查看到推送的镜像
ll /var/lib/registry/docker/registry/v2/repositories/nginx/
_layers # 其内每个目录都是一个镜像层, 每一层都单独推送, 单独存放
_manifests 
_uploads 
# node2上可以下载自己库中的镜像, 注意先修改自己的daemon.json, 使其docker也支持http
docker image pull node2:5000/nginx:v0.4

docker-compose

  • 单机编排工具

Compose is a tool for defining and running multi-container Docker
applications. With Compose, you use a Compose file to configure your
application's services. Then, using a single command, you create and
start all the services from your configuration

vmware harbor

  • 自建的经过美化的registry, 有GUI
harbor.png fether.png

feather: n. 羽毛 vt. 用羽毛装饰 vi. 长羽毛

自建并启动harbor

(0) 准备工作

yum -y install docker-compose # docker-compose基于epel仓库, python开发

wget https://storage.googleapis.com/harbor-releases/release-1.8.0/harbor-offline-installer-v1.8.2.tgz -P /usr/local/src/
tar -zxvf harbor-offline-installer-v1.8.2.tgz -C /usr/local/

(1)修改配置文件harbor.yml以符合实际需求

cd /usr/local/harbor/ && vi harbor.yml
hostname: reg.mydomain.com # 本机在互联网上不经常被访问的主机名或地址
jobservice:
  # Maximum number of job workers in job service  
  max_job_workers: 3  # 启动几个并发进程处理用户的上传下载请求, 
                      # 略小于等于核心CPU的个数

(2) 安装harbor, 比较耗时

./install.sh

ss -tnl # 可以看到物理机的80, 443, 4443端口被监听, 因为容器共享了物理机的ns

(3) 使用admin登录访问, 创建新用户和仓库, 然后使用新用户登录并创建项目, 在项目下可以创建名为testharbor的仓库

账号: admin 密码: Harbor12345

# 注意需要修改/etc/docker/daemon.json文件, 
# 添加自建的harbor server的ip和port到insecure-registries

# 登录自建的harbor, 按照提示输入密码
docker login http://node2:80 -u alex # 注意要写的规范, 这里强烈建议加上端口, 
                                     # 否则推送镜像时会出问题

# 按照harbor要求的格式打标签并推送
docker image tag redis:4-alpine node2:80/testharbor/redis:v0.2
docker image push node2:80/testharbor/redis[:v0.2] # 省略后面的tag时会将本地nginx仓库的
                                                   # 所有镜像都推送到harbor server

停止harbor

# 一般停止命令需要在docker-compose.yml文件所在目录执行
docker-compose pause # 暂停harbor服务
docker-compose unpause # 继续harbor服务
docker-compose stop # 停止harbor服务
docker-compose start # 启动harbor服务

相关文章

网友评论

      本文标题:6. docker私有registry

      本文链接:https://www.haomeiwen.com/subject/brwgectx.html