Docker 构建私有镜像仓库
在使用Docker一段时间后,往往会发现手头积累了大量的自定义镜像文件,这些文件通过公有仓库进行管理并不方便,另外有时候只是希望在内部用户之间进行分享,不希望暴露出去.这种情况下,就有必要搭建一个本地私有镜像仓库,本小结将具体介绍两个私有仓库的搭建,其中包括Registry,以及Vmware的Harbor企业仓库.
Registry 仓库搭建
Docker Registry工具是Docker内置的私有仓库解决方案,新版本的Registry基于Golang进行了重构,提供更好的性能和扩展性,并且支持Docker 1.6+的API,非常适合用来构建私有的镜像注册服务器.官方仓库中也提供了Registry的镜像,因此用户可以通过容器运行和源码安装两种方
式来使用Registry.
实验规划Docker服务器:192.168.1.5,Docker客户端:192.168.1.25,请在服务端配置好网桥服务.
◆服务端配置◆
1.将本机配置成网桥,使之能够互相通信.
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens32
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens32
DEVICE=eno16777728
TYPE=Ethernet
BOOTPROTO=static
BRIDGE=br0
NM_CONTROLLED=yes
ONBOOT=yes
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-br0
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-br0
TYPE=Bridge
DEVICE=br0
BOOTPROTO=static
IPADDR=192.168.1.15
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=8.8.8.8
DNS2=114.114.114.114
ONBOOT=yes
[root@localhost ~]# reboot
2.在服务端192.168.1.5上拉取registry镜像包.
[root@localhost ~]# docker pull registry:latest
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry latest 2e2f252f3c88 3 months ago 33.3MB
3.在服务端192.168.1.5运行docker私有仓库成功执行,则我们的docker私有仓库搭建成功.
[root@localhost ~]# docker run -itd -p 5000:5000 -v /registry:/var/lib/registry --restart=always --privileged=true --name my_registry registry:latest
◆客户端上传◆
1.此处我们以hello-world为例,首先要先把它拉取下来.
[root@localhost ~]# docker pull hello-world:latest
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/hello-world latest 4ab4c602aa5e 3 months ago 1.84 kB
2.其次给hello-world镜像打个tag表示新的版本,过程中指定服务器IP地址.
[root@localhost ~]# docker tag hello-world 192.168.1.5:5000/hello-world:latest
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.1.5:5000/hello-world latest 4ab4c602aa5e 3 months ago 1.84 kB
docker.io/hello-world latest 4ab4c602aa5e 3 months ago 1.84 kB
3.由于docker私有仓库服务器,默认是基于https传输的,所以我们需要在客户端192.168.1.25做相关设置,禁止使用https传输.
[root@localhost ~]# vim /etc/docker/daemon.json
{
"registry-mirrors": ["https://njrds9qc.mirror.aliyuncs.com"],
"insecure-registries":["192.168.1.5:5000"]
}
4.依次执行下面两条命令,重新启动docker让其加载我们的配置文件.
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl restart docker
[root@localhost ~]# systemctl enable docker
5.执行推送命令,将我们的hello-world推送到服务器上.
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.1.5:5000/hello-world latest 4ab4c602aa5e 3 months ago 1.84 kB
docker.io/hello-world latest 4ab4c602aa5e 3 months ago 1.84 kB
[root@localhost ~]# docker push 192.168.1.5:5000/hello-world:latest
The push refers to a repository [192.168.1.5:5000/hello-world]
428c97da766c: Pushed
latest: digest: sha256:1a6fd470b9ce10849be79e99529a88371dff60c60aab424c077007f6979b4812 size: 524
6.在服务器端查看刚刚提交的一个请求.
[root@localhost ~]# ls -l /registry/docker/registry/v2/repositories
total 0
drwxr-xr-x 5 root root 55 Dec 17 20:23 hello-world
[root@localhost ~]# curl http://192.168.1.5:5000/v2/_catalog
{"repositories":["hello-world"]}
◆客户端拉取◆
1.客户端修改一下配置文件,指定以下服务器地址.
[root@localhost ~]# cat /etc/docker/daemon.json
{
"registry-mirrors": ["https://njrds9qc.mirror.aliyuncs.com"],
"insecure-registries":["192.168.1.5:5000"]
}
2.修改Docker配置文件,开启局域网模式.
在/etc/default/docker添加一行:
DOCKER_OPTS="--insecure-registry 192.168.1.5:5000"
或在/etc/sysconfig/docker文件中添加
OPTIONS='--selinux-enabled --insecure-registry 192.168.1.5:5000'
3.重新启动Docker,加载配置文件.
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl restart docker
[root@localhost ~]# systemctl enable docker
4.通过命令下载测试镜像.
[root@localhost ~]# docker pull 192.168.1.5:5000/hello-world:latest
## Harbor 企业仓库搭建
Harbor是VMware公司开源的企业级DockerRegistry项目,项目地址为https://github.com/vmware/harbor.其目标是帮助用户迅速搭建一个企业级的DockerRegistry服务,它以Docker公司开源的registry为基础,提供了管理UI,基于角色的访问控制(Role BasedAccess Control),AD/LDAP集成、以及审计日志(Auditlogging)等企业用户需求的功能,同时还原生支持中文.Harbor的每个组件都是以Docker容器的形式构建的,使用DockerCompose来对它进行部署.用于部署Harbor的DockerCompose模板位于/Deployer/docker-compose.yml,由5个容器组成,这几个容器通过Dockerlink的形式连接在一起,在容器之间通过容器名字互相访问.对终端用户而言,只需要暴露proxy即Nginx的服务端口.
Proxy:由Nginx服务器构成的反向代理
Registry:由Docker官方的开源 registry 镜像构成的容器实例
UI:即架构中的core services,构成此容器的代码是 Harbor项目的主体
MySQL:由官方MySQL镜像构成的数据库容器
Log:运行着rsyslogd的容器,通过log-driver的形式收集其他容器的日志
Harbor特性
a、基于角色控制:用户和仓库都是基于项目进行组织的,而用户基于项目可以拥有不同的权限
b、基于镜像的复制策略:镜像可以在多个Harbor实例之间进行复制
c、支持LDAP:Harbor的用户授权可以使用已经存在LDAP用户
d、镜像删除,垃圾回收:Image可以被删除并且回收Image占用的空间,绝大部分的用户操作API方便用户对系统进行扩展
e、用户UI:用户可以轻松的浏览、搜索镜像仓库以及对项目进行管理
f、轻松的部署功能:Harbor提供了online、offline安装,除此之外还提供了virtualappliance安装
g、Harbor和 dockerregistry 关系:Harbor实质上是对 dockerregistry 做了封装,扩展了自己的业务模块
Harbor认证过程
a、dockerdaemon从dockerregistry拉取镜像
b、如果dockerregistry需要进行授权时,registry将会返回401Unauthorized响应,同时在响应中包含了docker
client如何进行认证的信息c、dockerclient根据registry返回的信息,向auth server发送请求获取认证token
d、auth server则根据自己的业务实现去验证提交的用户信息是否存符合业务要求
e、用户数据仓库返回用户的相关信息
f、auth server将会根据查询的用户信息,生成token令牌,以及当前用户所具有的相关权限信息.上述就是
完整的授权过程.当用户完成上述过程以后便可以执行相关的pull/push操作.认证信息会每次都带在请求头中
Harbor认证流程
a、首先,请求被代理容器监听拦截,并跳转到指定的认证服务器
b、如果认证服务器配置了权限认证,则会返回401.通知dockerclient在特定的请求中需要带上一个合法的token,而认证的逻辑地址则指向架构图中的core services
c、当dockerclient接受到错误code.client就会发送认证请求(带有用户名和密码)到coreservices进行basic
auth认证d、当C的请求发送给ngnix以后,ngnix会根据配置的认证地址将带有用户名和密码的请求发送到core
serivcese、coreservices获取用户名和密码以后对用户信息进行认证(自己的数据库或者介入LDAP都可以).成功以后,返回认证成功的信息
◆服务端配置◆
在服务端安装之前,请确保你的环境里面已安装好了Docker.
1.下载Docker-Compose工具,并移动到/usr/local/bin目录下.
[root@localhost ~]# wget https://github.com/docker/compose/releases/download/1.9.0/docker-compose-`uname -s`-`uname -m`
[root@localhost ~]# mv docker-compose /usr/local/bin/
[root@localhost ~]# chmod 777 -R /usr/local/bin/docker-compose
[root@localhost ~]# docker-compose --version
docker-compose version 1.9.0, build 2585387
2.下载HarBor解压并修改配置文件.
[root@localhost ~]# wget https://github.com/vmware/harbor/releases/download/v1.2.0/harbor-offline-installer-v1.2.0.tgz
[root@localhost ~]# tar -xzvf harbor-offline-installer-v1.2.0.tgz
[root@localhost ~]# cd harbor
[root@localhost harbor]# ls
common docker-compose.yml harbor.v1.2.0.tar.gz NOTICE
docker-compose.clair.yml harbor_1_1_0_template install.sh prepare
docker-compose.notary.yml harbor.cfg LICENSE upgrade
[root@localhost harbor]# vim harbor.cfg
hostname=192.168.1.5 #本机IP地址
ui_url_protocol=https
3.创建目录并到制定目录生成加密https证书.
[root@localhost ~]# mkdir -p /data/cert
[root@localhost ~]# chmod 777 /data/cert
[root@localhost ~]# cd /data/cert
[root@localhost ~]# openssl genrsa -des3 -out server.key 2048
[root@localhost ~]# openssl req -new -key server.key -out server.csr
[root@localhost ~]# cp server.key server.key.org
[root@localhost ~]# openssl rsa -in server.key.org -out server.key
[root@localhost ~]# openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
4.安装并拷贝相关配置文件,最后进入测试页测试效果.
[root@localhost ~]# cd /root/harbor
[root@localhost harbor]# ./install.sh
[root@localhost ~]# curl https://192.168.1.5
#用户名:admin 密码:Harbor12345
◆客户端上传◆
1.客户端需要指定镜像仓库地址(也就是服务器的地址).
[root@localhost ~]# vim /etc/docker/daemon.json
{
"insecure-registries": ["192.168.1.5"]
}
[root@localhost ~]# systemctl restart docker
2.下载一个hello-world镜像,并给镜像重新打标签.
[root@localhost ~]# docker pull hello-world:latest
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/hello-world latest 4ab4c602aa5e 3 months ago 1.84 kB
[root@localhost ~]# docker tag hello-world:latest 192.168.1.5/library/hello-world:latest
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.1.5/library/hello-world latest 4ab4c602aa5e 3 months ago 1.84 kB
docker.io/hello-world latest 4ab4c602aa5e 3 months ago 1.84 kB
3.登陆进行上传测试.
[root@localhost ~]# docker login 192.168.1.5
Username: admin
Password: Harbor12345
Login Succeeded
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.1.5/library/hello-world latest 4ab4c602aa5e 3 months ago 1.84 kB
docker.io/hello-world latest 4ab4c602aa5e 3 months ago 1.84 kB
[root@localhost ~]# docker push 192.168.1.5/library/hello-world:latest
The push refers to a repository [192.168.1.5/library/hello-world]
428c97da766c: Pushed
latest: digest: sha256:1a6fd470b9ce10849be79e99529a88371dff60c60aab424c077007f6979b4812 size: 524
◆客户端拉取◆
1.指定镜像仓库地址,指定镜像仓库地址.
[root@localhost ~]# vim /etc/docker/daemon.json
{ "insecure-registries": ["192.168.1.5"] } #指定服务器地址
2.下载测试镜像,这里下载刚刚上传的试一下.
[root@localhost ~]# docker pull 192.168.1.5/library/hello-world:latest
Trying to pull repository 192.168.1.5/library/hello-world ...
latest: Pulling from 192.168.1.5/library/hello-world
d1725b59e92d: Pull complete
Digest: sha256:1a6fd470b9ce10849be79e99529a88371dff60c60aab424c077007f6979b4812
Status: Downloaded newer image for 192.168.1.5/library/hello-world:latest
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.1.5/library/hello-world latest 4ab4c602aa5e 3 months ago 1.84 kB
参考文献:《Docker技术入门与实战》《Docker基础与实战》
Docker 构建私有镜像仓库的更多相关文章
- Docker创建私有镜像仓库
Docker官方提供了一个工具docker-registry,可以借助这个工具构建私有镜像仓库: 1.拉取registry镜像 # docker pull registry//可以使用 docker ...
- 利用docker实现私有镜像仓库
利用docker实现私有镜像仓库 在linux服务器上安装了docker过后,可以拉取docker镜像仓库: docker pull registry 再执行命令让镜像run起来: docker ru ...
- 搭建docker registry私有镜像仓库
搭建docker registry私有镜像仓库 一.安装docker-distribution yum install -y docker-distribution 安装完成后,启动服务: syste ...
- 手动搭建Docker本地私有镜像仓库
实验环境:两个Centos7虚拟机,一个是Server,用作客户端,另一个是Registry,用作Docker私有镜像仓库. 基础配置 查看一下两台虚拟机的IP地址 Server的IP地址是192.1 ...
- docker配置私有镜像仓库-registry和hyper/docker-registry-web
1.前言️ Docker hub是远程仓库,是国外的,push pull速度特别慢,尤其是网速不好的时候,页面都点不进去,官网 但是可以配置阿里云镜像加速哦: 因此搭建一个私有的镜像仓库用于管理我们 ...
- docker实战——Docker本地私有镜像仓库Harbor搭建及配置
Harbor介绍 Docker容器应用的开发和运行离不开可靠的镜像管理,虽然docker官方提供了公共的镜像仓库(Docker Hub),但是从安全和效率等方面考虑,部署我们私有环境内的Registr ...
- 使用Nexus3构建Docker私有镜像仓库
一.安装Nexus3 Nexus3是Sonatype提供的仓库管理平台,Nuexus Repository OSS3能够支持Maven.npm.Docker.YUM.Helm等格式数据的存储和发布:并 ...
- 容器技术之Docker私有镜像仓库docker-distribution
在前边的博客中我们说到docker的架构由docker客户端.服务端以及仓库组成:docker仓库就是用来存放镜像的地方:其实docker registry我们理解为存放docker镜像仓库的仓库比较 ...
- 容器技术之Docker私有镜像仓库harbor
前文我们聊到了docker的私有镜像仓库docker-distribution的搭建和简单的使用,回顾请参考https://www.cnblogs.com/qiuhom-1874/p/13058338 ...
随机推荐
- IE 不兼容 console 关键字
如果在JS文件中写了console.log()方法,在IE下打开 开发者工具就没问题,不打开就有问题js 报错 不执行等等 ...... (IE这都是什么鬼!!),百度过后的解决方法如下: 好吧,这其 ...
- smarty逻辑运算符
smarty逻辑运算符 eq equal : 相等 neq not equal:不等于 gt greater than:大于 lt less th ...
- P2983 [USACO10FEB]购买巧克力
P2983 [USACO10FEB]购买巧克力 题解 注意题目开 long long 贪心策略:价格从低到高,买够为止 反证:若剩下的有一个K”,比K小,那么交换,稳赚不赔 所以,在买K之前,所有比他 ...
- [SQL 高级查询运算符的用法 UNION (ALL),EXCEPT(ALL),INTERSECT(ALL) ]
今天看到 三个查询运算符,给大家分享分享 为此我建立了两张表分别为 Articles 和 newArticles 我建立的时候,只建立了一张表 Articles ,表 newArticles 是 ...
- web搜索框的制作(必应)
搜索框中我们输入一些字或者字母,为何下面就会有一些自动补齐的相关搜索,比如我在搜索输入框中输入一个字母e,下面就会出现饿了么,e租宝,ems等相关的搜索链接.然后经过百度,发现原来很多厂商的服务器早已 ...
- 批量替换word内容
有一个需求需要把word中的一段文档的编号批量替换 如,把133-183批量的替换成31-81,需要批量的替换word,脚本如下 from docx import Document import os ...
- layui时间控件选择时间范围
layui.use([ 'laydate'], function(){ var $ = layui.$; var laydate = layui.laydate; var max = ${nowYea ...
- androidstudio导入新项目build tools不符合问题解决
问题描述:从网上或者其他地方拷贝来完整代码导入androidstudio的时候,gradle过程显示build tools不符合 问题分析:你安装的SDK版本可能与其他人不一样,那么build的工具也 ...
- go 基础 处理异常
package main import "fmt" func main() { dosomething() } func dosomething(){ defer func() { ...
- php文件夹上传下载控件分享
用过浏览器的开发人员都对大文件上传与下载比较困扰,之前遇到了一个php文件夹上传下载的问题,无奈之下自己开发了一套文件上传控件,在这里分享一下.希望能对你有所帮助. 以下是实例的部分脚本文件 这里我先 ...