设为首页 收藏本站
查看: 957|回复: 0

[经验分享] centos7搭建docker私有仓库

[复制链接]

尚未签到

发表于 2017-12-6 13:51:44 | 显示全部楼层 |阅读模式
  1.环境:



[iyunv@docker02 anchors]# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)


[iyunv@docker02 anchors]# docker info
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 3
Server Version: 17.03.1-ce
.....


10.60.10.39     docker01.lo   -->仓库
10.60.10.40     docker02.lo   -->客户端
10.60.10.41     docker03.lo   -->客户端
  2.仓库配置https认证
  a.配置hosts文件


[iyunv@docker01 ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
10.60.10.39docker01.lo
10.60.10.40     docker02.lo
10.60.10.41     docker03.lo

  b.生成证书



[iyunv@docker01 ~]# cd /etc/docker/
[iyunv@docker01 docker]# mkdir certs
#切到docker配置文件目录,新建certs目录。


[iyunv@docker01 docker]# openssl req -newkey rsa:4096 -nodes -sha256 -keyout certs/docker01.lo.key -x509 -days 365 -out certs/docker01.lo.crt
Generating a 4096 bit RSA private key
..........................................................................................................................................................................................................................................................................++
..............++
writing new private key to 'certs/docker01.lo.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN  
State or Province Name (full name) []:ZJ
Locality Name (eg, city) [Default City]:HZ
Organization Name (eg, company) [Default Company Ltd]:ZX
Organizational Unit Name (eg, section) []:ZX
Common Name (eg, your name or your server's hostname) []:docker01.lo
Email Address []:TEST@163.com
  注意,以上红色字体的三处关键字要一致,这里我用得是仓库主机的主机名。



[iyunv@docker01 docker]# ll certs/
total 8
-rw-r--r--. 1 root root 2049 Jun 19 14:41 docker01.lo.crt
-rw-r--r--. 1 root root 3272 Jun 19 14:41 docker01.lo.key
  3.运行registry容器



docker run -d -P -it -p 5000:5000 --restart=always  --name registry_https01 -v `pwd`/certs:/etc/docker/certs/ -e REGISTRY_HTTP_TLS_CERTIFICATE=/etc/docker/certs/docker01.lo.crt  -e REGISTRY_HTTP_TLS_KEY=/etc/docker/certs/docker01.lo.key registry


[iyunv@docker01 docker]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
4b10b23f3dd0        registry            "/entrypoint.sh /e..."   52 seconds ago      Up 52 seconds       0.0.0.0:5000->5000/tcp   registry_https01


[iyunv@docker01 docker]# netstat -ntpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name   
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      852/sshd            
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1559/master         
tcp6       0      0 :::22                   :::*                    LISTEN      852/sshd            
tcp6       0      0 ::1:25                  :::*                    LISTEN      1559/master         
tcp6       0      0 :::9022                 :::*                    LISTEN      2154/dockerd        
tcp6       0      0 :::5000                 :::*                    LISTEN      5545/docker-proxy   
tcp6       0      0 :::2377                 :::*                    LISTEN      2154/dockerd        
tcp6       0      0 :::7946                 :::*                    LISTEN      2154/dockerd  
  4.配置客户端( 需要配置hosts文件如步骤2-a)
  a.远程拷贝docker01.lo.crt到客户端/etc/pki/ca-trust/source/anchors目录下



[iyunv@docker01 docker]# scp certs/docker01.lo.crt 10.60.10.40:/etc/pki/ca-trust/source/anchors
root@10.60.10.40's password:
docker01.lo.crt                                                                                                                                            100% 2049     2.0KB/s   00:00   
[iyunv@docker01 docker]# scp certs/docker01.lo.crt 10.60.10.41:/etc/pki/ca-trust/source/anchors
root@10.60.10.41's password:
docker01.lo.crt                                                                                                                                            100% 2049     2.0KB/s   00:00
  b.更新证书



[iyunv@docker02 ~]# cd /etc/pki/ca-trust/source/anchors
[iyunv@docker02 anchors]# update-ca-trust


[iyunv@docker03 ~]# cd /etc/pki/ca-trust/source/anchors
[iyunv@docker03 anchors]# update-ca-trust
  c.上传image



[iyunv@docker02 anchors]# docker images
REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
nginx                   latest              958a7ae9e569        2 weeks ago         109 MB
swarm                   latest              36b1e23becab        5 months ago        15.9 MB
centos                  6.8                 0cd976dc0a98        9 months ago        195 MB



[iyunv@docker02 anchors]# docker tag centos:6.8 docker01.lo:5000/centos:6.8
[iyunv@docker02 anchors]# docker push docker01.lo:5000/centos
The push refers to a repository [docker01.lo:5000/centos]
b1b065555b8a: Pushed
6.8: digest: sha256:c338f851dc6520fc3f7ece01e4fbe207eaa78b775a0738f2bfdd6f36144e6b8a size: 529


[iyunv@docker02 anchors]# curl https://docker01.lo:5000/v2/_catalog
{"repositories":["centos"]}
  -----------------------------------------------------------------------------



[iyunv@docker03 anchors]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu              latest              7b9b13f7b9c0        2 weeks ago         118 MB
nginx               latest              958a7ae9e569        2 weeks ago         109 MB
swarm               latest              36b1e23becab        5 months ago        15.9 MB
centos              6.8                 0cd976dc0a98        9 months ago        195 MB


[iyunv@docker03 anchors]# docker tag ubuntu docker01.lo:5000/ubuntu
[iyunv@docker03 anchors]# docker push docker01.lo:5000/ubuntu
The push refers to a repository [docker01.lo:5000/ubuntu]
d8b353eb3025: Pushed
f2e85bc0b7b1: Pushed
fc9e1e5e38f7: Pushed
fe9a3f9c4559: Pushed
6a8bf8c8edbd: Pushed
latest: digest: sha256:ea1d854d38be82f54d39efe2c67000bed1b03348bcc2f3dc094f260855dff368 size: 1357


[iyunv@docker03 anchors]# curl https://docker01.lo:5000/v2/_catalog
{"repositories":["centos","ubuntu"]}
  d.下载image



[iyunv@docker02 anchors]# docker images
REPOSITORY                TAG                 IMAGE ID            CREATED             SIZE
nginx                     latest              958a7ae9e569        2 weeks ago         109 MB
swarm                     latest              36b1e23becab        5 months ago        15.9 MB
centos                    6.8                 0cd976dc0a98        9 months ago        195 MB
docker01.lo:5000/centos   6.8                 0cd976dc0a98        9 months ago        195 MB


[iyunv@docker02 anchors]# docker pull docker01.lo:5000/ubuntu
Using default tag: latest
latest: Pulling from ubuntu
bd97b43c27e3: Pull complete
6960dc1aba18: Pull complete
2b61829b0db5: Pull complete
1f88dc826b14: Pull complete
73b3859b1e43: Pull complete
Digest: sha256:ea1d854d38be82f54d39efe2c67000bed1b03348bcc2f3dc094f260855dff368
Status: Downloaded newer image for docker01.lo:5000/ubuntu:latest


[iyunv@docker02 anchors]# docker images
REPOSITORY                TAG                 IMAGE ID            CREATED             SIZE
docker01.lo:5000/ubuntu   latest              7b9b13f7b9c0        2 weeks ago         118 MB
nginx                     latest              958a7ae9e569        2 weeks ago         109 MB
swarm                     latest              36b1e23becab        5 months ago        15.9 MB
centos                    6.8                 0cd976dc0a98        9 months ago        195 MB
docker01.lo:5000/centos   6.8                 0cd976dc0a98        9 months ago        195 MB
  -------------------------------------------------



[iyunv@docker03 anchors]# docker images
REPOSITORY                TAG                 IMAGE ID            CREATED             SIZE
docker01.lo:5000/ubuntu   latest              7b9b13f7b9c0        2 weeks ago         118 MB
ubuntu                    latest              7b9b13f7b9c0        2 weeks ago         118 MB
nginx                     latest              958a7ae9e569        2 weeks ago         109 MB
swarm                     latest              36b1e23becab        5 months ago        15.9 MB
centos                    6.8                 0cd976dc0a98        9 months ago        195 MB


[iyunv@docker03 anchors]# docker pull docker01.lo:5000/centos:6.8
6.8: Pulling from centos
Digest: sha256:c338f851dc6520fc3f7ece01e4fbe207eaa78b775a0738f2bfdd6f36144e6b8a
Status: Downloaded newer image for docker01.lo:5000/centos:6.8


[iyunv@docker03 anchors]# docker images
REPOSITORY                TAG                 IMAGE ID            CREATED             SIZE
docker01.lo:5000/ubuntu   latest              7b9b13f7b9c0        2 weeks ago         118 MB
ubuntu                    latest              7b9b13f7b9c0        2 weeks ago         118 MB
nginx                     latest              958a7ae9e569        2 weeks ago         109 MB
swarm                     latest              36b1e23becab        5 months ago        15.9 MB
centos                    6.8                 0cd976dc0a98        9 months ago        195 MB
docker01.lo:5000/centos   6.8                 0cd976dc0a98        9 months ago        195 MB
  5.问题解决:


[iyunv@docker03 anchors]# docker push docker01.lo:5000/centos
The push refers to a repository [docker01.lo:5000/centos]
Get https://docker01.lo:5000/v1/_ping: x509: certificate signed by unknown authority

  如碰到上述问题:



[iyunv@docker03 anchors]# cat docker01.l.crt >> /etc/pki/tls/certs/ca-bundle.crt
[iyunv@docker03 anchors]# update-ca-trust
[iyunv@docker03 anchors]# systemctl restart docker

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-421335-1-1.html 上篇帖子: oracle11在docker环境下的运行 下篇帖子: docker命令查询
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表