Docker Registry分类
- Registry用于保存docker镜像,包括镜像的层次结构和元数据
分类
Sponsor Registry:第三方red=gistry,供客户和Docker社区使用
Mirror Registry:第三方,只供客户使用
Vendor Registry:由发布Docker镜像的供应商提供的
Private Registry:通过设有防火墙和额外的安全层的私有实体提供的registry
创建Docker 私有仓库
docker官方提供了一个私有仓库的镜像registry。
主机安装
安装部署
# yum -y install docker-registry# vim /etc/docker-distribution/registry/config.ymlversion: 0.1log:fields:service: registrystorage:cache:layerinfo: inmemoryfilesystem:rootdirectory: /var/lib/registryhttp:addr: :5000# systemctl start docker-distribution # 启动服务
验证推送 ```bash
查看本地镜像
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest 540a289bab6c 2 weeks ago 126MB redis latest de25a81a5a0b 3 weeks ago 98.2MB
通过docker tag将该镜像标志为要推送到私有仓库:
docker tag nginx:latest localhost:5000/nginx:latest
推送镜像到私有仓库
docker push localhost:5000/nginx
The push refers to repository [localhost:5000/nginx] a89b8f05da3a: Pushed 6eaad811af02: Pushed b67d19e65ef6: Pushed latest: digest: sha256:f56b43e9913cef097f246d65119df4eda1d61670f7f2ab720831a01f66f6ff9c size: 948
- 默认私有registry启动为http协议,提交时可能会报错,可设置为https或者设置为忽略https```bash# vim /etc/docker/daemon.json{"registry-mirrors": ["http://hub-mirror.c.163.com"]"insecure-registries": ["localhost:5000"] # 增加}
容器安装
- docker pull
# docker pull registry:2 # docker run -d -v /opt/registry:/var/lib/registry -p 5000:5000 --name myregistry registry:2
- docker pull
Harbor
- docker 官方提供的私有仓库 registry,用起来虽然简单 ,但在管理的功能上存在不足。 Harbor是一个用于存储和分发Docker镜像的企业级Registry服务器,harbor使用的是官方的docker registry(v2命名是distribution)服务去完成。harbor在docker distribution的基础上增加了一些安全、访问控制、管理的功能以满足企业对于镜像仓库的需求。
Harbor的部署一般分为两种离线和在线
- Online installer: The online installer downloads the Harbor images from Docker hub. For this reason, the installer is very small in size.
- Offline installer: Use the offline installer if the host to which are are deploying Harbor does not have a connection to the Internet. The offline installer contains pre-built images so it is larger than the online installer.
- Harbor官方github地址:https://github.com/goharbor/harbor/
特点
- 支持基于用户的访问控制
- 支持镜像复制高可用
- 支持图形化用户界面
- 支持用户认证管理
- 有丰富的Restful API
Harbor安装
Harbor安装运行需要借助docker compose单机编排工具
docker compose 可以轻松、高效的管理容器,它是一个用于定义和运行多容器 Docker 的应用程序工具
# yum -y install epel-release # yum -y install docker-compose安装Harbor
# tar -zxf harbor.v1.9.2.tar.gz # vim harbor.cfg hostname = 192.168.10.11 ui_url_protocol = https db_password = root123 max_job_workers = 3 customize_crt = on ssl_cert = /data/db/cert/www.biglittleant.cn.crt ssl_cert_key = /data/db/cert/www.biglittleant.cn.key secretkey_path = /data/db # sh ./install.sh
hostname:配置主机名称,不可以设置127.0.0.1,localhost这样的主机名,ui_url_protocol:指定使用HTTP协议还是HTTPS协议。Email settings:设置harbor的邮箱。harbor_admin_password:设置管理员的初始密码auth_mode:用户认证模式,默认是db_auth,也可以使用ldap验证。db_password:使用db需要指定连接数据库的密码self_registration:是否允许自行注册用户,默认是on,新版本可以在图形界面中修改。max_job_workers:最大工作数,默认是三个
# docker-compose stop
# docker-compose up -d
