博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
docker仓库
阅读量:3962 次
发布时间:2019-05-24

本文共 7874 字,大约阅读时间需要 26 分钟。

docker仓库

:初步了解仓库是如何管理的。

:可以注册一个官方仓库来上传自己写好的镜像和拉取想要的镜像。
:docker官方文档教你如何Deploy a registry server。
:提供了一个可视化的仓库管理界面。

  • Docker 仓库是用来包含镜像的位置,Docker提供一个注册服务器(Register)来保存多个仓库,每个仓库又可以包含多个具备不同tag的镜像。Docker运行中使用的默认仓库是 Docker Hub 公共仓库。
  • registry的工作原理:一次docker pull 或 push背后发生的事情
    index服务主要提供镜像索引以及用户认证的功能。当下载一个镜像的时候,首先会去index服务上做认证,然后查找镜像所在的registry的地址并放回给docker客户端,docker客户端再从registry下载镜像,在下载过程中 registry会去index校验客户端token的合法性,不同镜像可以保存在不同的registry服务上,其索引信息都放在index服务上。
  • Docker Registry有三个角色,分别是index、registry和registry client。
  • index
    负责并维护有关用户帐户、镜像的校验以及公共命名空间的信息。
    Web UI
    元数据存储
    认证服务
    符号化
  • registry
    是镜像和图表的仓库,它不具有本地数据库以及不提供用户认证,通过Index Auth service的Token的方式进行认证。
  • Registry Client
    Docker充当registry客户端来维护推送和拉取,以及客户端的授权。

搭建一个私有仓库

##下载registry镜像[root@server1 ~]# docker search registry[root@server1 ~]# docker pull registry  [root@server1 ~]# docker images registry[root@server1 ~]# docker ps -a[root@server1 ~]# docker stop webserverwebserver[root@server1 ~]# docker rm webserver[root@server1 ~]# docker history registry:latest

##运行registry容器[root@server1 ~]# docker run -d --name registry -p 5000:5000 -v /opt/registry:/var/lib/registry registry  [root@server1 ~]# docker ps[root@server1 ~]# netstat -antlp[root@server1 ~]# ll -d /opt/registry/

上传镜像到本地仓库,本地镜像在命名时需要加上仓库的ip和端口[root@server1 ~]# docker tag webserver:v4 localhost:5000/webserver:latest[root@server1 ~]# docker imagesREPOSITORY                        TAG       IMAGE ID       CREATED        SIZEwebserver                         v4        047ab2e35274   15 hours ago   31.7MBlocalhost:5000/webserver          lastest   047ab2e35274   15 hours ago   31.7MB[root@server1 ~]# docker push localhost:5000/webserver[root@server1 ~]# tree /opt/registry/[root@server1 ~]# curl localhost:5000/v2/_catalog{
"repositories":["webserver"]}

远程连接私有仓库

server2上首先安装docker-ce,并且开机自启。[root@server2 yum.repos.d]# cd /etc/docker/[root@server2 docker]# lskey.json[root@server2 docker]# vim daemon.json{
"insecure-registries" : ["192.168.0.1:5000"]}[root@server2 docker]# systemctl reload docker[root@server2 docker]# docker pull 192.168.0.1:5000/webserver[root@server2 docker]# docker images[root@server2 docker]# docker tag 192.168.0.1:5000/webserver webserver[root@server2 docker]# docker run -d webserver

签名加密

[root@server2 docker]# rm -fr daemon.json[root@server2 docker]# systemctl reload docker生成自己的证书[root@server1 ~]# mkdir  -p  certs[root@server1 ~]# openssl req \> -newkey rsa:4096 -nodes -sha256 -keyout certs/westos.org.key \> -x509 -days 365 -out certs/westos.org.crt域名westos.org要求在主机上有解析[root@server1 ~]# docker stop registry[root@server1 ~]# docker rm registry

[root@server1 ~]# vim /etc/hosts      ##加上reg.westos.org解析,server2相同将westos.org..crt文件复制到 /etc/docker/certs.d/reg.westos.org/ca.crt每个Docker主机上。您无需重启Docker。[root@server1 ~]# mkdir  /etc/docker/certs.d/reg.westos.org -p[root@server2 ~]# mkdir  /etc/docker/certs.d/reg.westos.org -p[root@server1 ~]# cp certs/westos.org.crt /etc/docker/certs.d/reg.westos.org/ca.crt拷贝证书到其他docker主机[root@server1 ~]# cd /etc/docker/certs.d/reg.westos.org/[root@server1 reg.westos.org]# scp ca.crt server2:/etc/docker/certs.d/reg.westos.org/重新启动注册表,将其定向为使用TLS证书。此命令将certs/目录绑定安装到容器中的/certs/,并设置环境变量,该变量告诉容器在何处找到domain.crt anddomain.key文件。注册表在端口443(默认的HTTPS端口)上运行。[root@server1 ~]# docker run -d --name registry -p 443:443 -v /opt/registry:/var/lib/registry -v "$(pwd)"/certs:/certs -e REGISTRY_HTTP_ADDR=0.0.0.0:443 -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/westos.org.crt -e REGISTRY_HTTP_TLS_KEY=/certs/westos.org.key registry

测试

server1上传,server2下载

[root@server1 ~]# docker tag busybox:latest reg.westos.org/busybox:latest[root@server1 ~]# docker push reg.westos.org/busybox:latest[root@server2 ~]# docker pull reg.westos.org/busybox:latest

本地认证

[root@server1 ~]# mkdir auth[root@server1 ~]# yum provides */htpasswd[root@server1 ~]# yum install -y httpd-tools[root@server1 ~]# htpasswd -c -B auth/htpasswd linux[root@server1 ~]# htpasswd -B auth/htpasswd admin[root@server1 ~]# cat auth/htpasswd [root@server1 ~]# docker run -d --name registry -p 443:443 -v /opt/registry:/var/lib/registry -v "$(pwd)"/certs:/certs -e REGISTRY_HTTP_ADDR=0.0.0.0:443 -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/westos.org.crt -e REGISTRY_HTTP_TLS_KEY=/certs/westos.org.key -v "$(pwd)"/auth:/auth -e "REGISTRY_AUTH=htpasswd" -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" -e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd registry[root@server1 ~]# ls certs/westos.org.crt  westos.org.key[root@server1 ~]# docker ps[root@server1 ~]# docker tag ubuntu:latest reg.westos.org/ubuntu:latest

harbor仓库

.

部署:(依赖性 docker 17.06.0-ce+ and docker-compose 1.18.0+)

[root@server1 ~]# tar zxf harbor-offline-installer-v1.10.1.tgz [root@server1 ~]# cd harbor/[root@server1 harbor]# mv docker-compose-Linux-x86_64-1.27.0 /usr/local/bin/docker-compose[root@server1 harbor]# chmod +x /usr/local/bin/docker-compose[root@server1 harbor]# docker rm -f registry[root@server1 ~]# cp -r certs/ /      ##因为下面配置文件里我选择了放在/下,所以这里将证书复制到根下了。
[root@server1 harbor]# vim harbor.yml        ## 修改内容如下hostname: reg.westos.org  certificate: /certs/westos.org.crt  private_key: /certs/westos.org.keyharbor_admin_password: westos

[root@server1 harbor]# ./install.sh --help[root@server1 harbor]# ./install.sh [root@server1 harbor]# docker ps[root@server1 harbor]# docker-compose ps

[root@server1 harbor]# docker logout reg.westos.orgRemoving login credentials for reg.westos.org[root@server1 harbor]# cat ~/.docker/config.json {
"auths": {
}[root@server1 harbor]#docker login reg.westos.orgUsername: admin[root@server1 harbor]# docker tag busybox:latest reg.westos.org/library/busybox:latest[root@server1 harbor]# docker push reg.westos.org/library/busybox:latest

[root@server2 ~]# cd /etc/docker/[root@server2 docker]# vim daemon.json{
"registry-mirrors": ["https://reg.westos.org"]}[root@server2 docker]# systemctl reload docker[root@server2 docker]# docker pull busybox

建立私有仓库并设置维护人员和访客

[root@server1 data]# docker logout reg.westos.org[root@server1 data]# docker login reg.westos.orgUsername: linux  ##维护人员[root@server1 data]# docker tag ubuntu:latest reg.westos.org/westos/ubuntu:latest[root@server1 data]# docker push reg.westos.org/westos/ubuntu:latest

[root@server2 docker]# docker logout reg.westos.orgRemoving login credentials for reg.westos.org[root@server2 docker]# docker login reg.westos.orgUsern[root@server2 docker]# docker tag webserver:latest reg.westos.org/westos/webserver:latest[root@server2 docker]# docker push reg.westos.org/westos/webserver:latestusername: demo ##访客[root@server2 docker]# docker tag webserver:latest reg.westos.org/westos/webserver:latest[root@server2 docker]# docker push reg.westos.org/westos/webserver:latest

配置中加入镜像扫描、内容信任等选项

[root@server1 harbor]# docker-compose down [root@server1 harbor]# ./prepare  #清理[root@server1 harbor]# ./install.sh --with-notary --with-clair --with-chartmuseum[root@server1 harbor]# docker-compose ps
  • 配置中加入了漏洞扫描,内容信任以及helm charts等选项,helm charts是为了之后的k8s做准备。
手动进行扫描,扫描太耗费内存的,所以不建议开启扫描功能。[root@server1 harbor]# docker login reg.westos.orgUsername: admin[root@server1 harbor]# docker push reg.westos.org/library/game2048:latest

  • 启用docker内容信任
部署根证书:[root@server1 ~]# mkdir ~/.docker/tls/reg.westos.org:4443 -p[root@server1 ~]# cd ~/.docker/tls/reg.westos.org:4443[root@server1 reg.westos.org:4443]# cp /etc/docker/certs.d/reg.westos.org/ca.crt .启用docker内容信任:export DOCKER_CONTENT_TRUST=1export DOCKER_CONTENT_TRUST_SERVER=https://reg.westos.org:4443上传镜像:[root@server1 ~]# docker tag yakexi007/game2048:latest reg.westos.org/library/game2048:latest[root@server1 ~]# docker push reg.westos.org/library/game2048:latest当我们修改镜像的名字的时候需要我们输入root key 当我们只修改标签的时候,我们只用输入repository key

为了不让扫描,使得占用的空间越来越大,所以重新修改一下选项[root@server1 ~]# export DOCKER_CONTENT_TRUST=0[root@server1 harbor]# docker-compose down[root@server1 harbor]# ./prepare[root@server1 harbor]# ./install.sh  --with-chartmuseum

转载地址:http://enhzi.baihongyu.com/

你可能感兴趣的文章
如何查看进程的信息(线程数)
查看>>
Linux中的chage命令
查看>>
linux-详细解析密码文件passwd与shadow
查看>>
su- 与su的区别
查看>>
linux下发邮件mail
查看>>
echo如何手动输出换行
查看>>
身份证的正确使用方法——非常重要的知识
查看>>
ExtJS & Ajax
查看>>
Tomcat在Windows下的免安装配置
查看>>
JMeter常用测试元件
查看>>
JMeter——使用技巧
查看>>
Hibernate 实体层设计--Table per subclass
查看>>
JavaScriptHelper之 observe_field
查看>>
JavaScriptHelper之 periodically_ajax_tag
查看>>
Ruby on Rails(ROR) 小结(一) 绑定controller and view
查看>>
Ruby on Rails(ROR) 小结(一) 通过Schema Migrations来创建数据表
查看>>
form表单post请求发送及回收
查看>>
confluence5.8.10 安装与破解
查看>>
Testlink使用文档
查看>>
Ruby on Rails(ROR) 实例开发之一 配置数据库Mysql
查看>>