设为首页 收藏本站
云服务器等爆品抢先购,低至4.2元/月
查看: 796|回复: 0

[经验分享] docker仓库

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2017-8-21 10:55:37 | 显示全部楼层 |阅读模式
Docker仓库
仓库(Repository)是集中存放镜像的地方
Docker Hub 官方仓库
目前 Docker 官方维护了一个公共仓库 Docker Hub,其中已经包括了超过 15,000 的镜像。大部分需求,都可以通过在 Docker Hub 中直接下载镜像来实现。
一基本操作
可通过docker search 命令来查找官方仓库中的镜像,也可以使用本地tar包
先删除yum pid  关闭防火墙
1
2
3
[iyunv@localhost /]# rm -rf /var/run/yum.pid
[iyunv@localhost /]# systemctl stop firewalld.service
[iyunv@localhost /]# yum -y install docker



1)下载到本地,docker pull  或者使用tar包载入
1
2
3
4
[iyunv@localhost /]# docker load < centos6.tar
[iyunv@localhost /]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
docker.io/centos    centos6             cf2c3ece5e41        13 months ago       194.6 MB



私有仓库https支持:
1)安装依赖软件包:
1
[iyunv@localhost /]# yum -y install pcre-devel zlib-devel openssl openssl-devel




在Nginx编译需要PCRE,因为Nginx的Rewrite模块和HTTP核心模块会使用到PCRE正则表达式。需要安装pcre和pcre-devel用yum就能安装。
Zlib库提供了开发人员的压缩算法,在nginx的模块中需要使用gzip压缩。
需要安装zlib和zlib-devel用yum就可以安装
在Nginx中如果需要为服务器提供安全则需要用到OpenSSL库。
需要安装的是openssl和openssl-devel。用yum就可以安装。
2)编辑/etc/hosts,把docker.benet.com的ip地址添加进来
主机名、ip地址: vim /etc/hosts 添加
1
192.168.100.33 docker.benet.com



3) 生成根密钥
先把/etc/pki/CA/cacert.pem
/etc/pki/CA/index.txt
/etc/pki/CA/index.txt.attr
/etc/pki/CA/index.txt.old
/etc/pki/CA/serial
/etc/pki/CA/serial.old
删除掉!
1
2
3
[iyunv@localhost CA]# openssl genrsa -out private/cakey.pem 2048
[iyunv@localhost CA]# ls private/
Cakey.pem



3) 生成根证书
1
[iyunv@localhost CA]# openssl req -new -x509 -key private/cakey.pem -out cacert.pem



Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:xinwang
Locality Name (eg, city) [Default City]:xinwang
Organization Name (eg, company) [Default Company Ltd]:wang
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:docker.benet.com
Email Address []:

4)会提示输入一些内容,因为是私有的,所以可以随便输入,最好记住能与后面保持一致,特别是"Common Name”。必须要和hostname显示的一致。
上面的自签证书cacert.pem应该生成在/etc/pki/CA下。
1
2
[iyunv@localhost CA]# ls
cacert.pem  certs  crl  newcerts  private



5)为nginx web服务器生成ssl密钥
1
2
3
[iyunv@localhost CA]# mkdir /etc/pki/CA/ssl
[iyunv@localhost CA]# cd /etc/pki/CA/ssl/
[iyunv@localhost ssl]# openssl genrsa -out nginx.key 2048



注:因为CA中心与要申请证书的nginx服务器是同一个所以就在本机上执行为nginx服务器生成ssl密钥了,否则应该是在另一台需要用到证书的服务器上生成。
查看nginx服务器的密钥
1
2
[iyunv@localhost ssl]# ls
nginx.key



6) 为nginx生成证书签署请求
执行
1
[iyunv@localhost ssl]# openssl req -new -key nginx.key -out nginx.csr



Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:xinwang
Locality Name (eg, city) [Default City]:xinwang
Organization Name (eg, company) [Default Company Ltd]:wang
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:docker.benet.com
Email Address []:
同样会提示输入一些内容,Commone Name一定要是你要授予证书的服务器域名或主机名,challenge password不填。
7) 私有CA根据请求来签发证书
1
2
3
[iyunv@localhost ssl]# touch /etc/pki/CA/index.txt
[iyunv@localhost ssl]# touch /etc/pki/CA/serial
[iyunv@localhost ssl]# echo 00 > /etc/pki/CA/serial



1
[iyunv@localhost ssl]# openssl ca -in nginx.csr -out nginx.crt




Signature ok
Subject:
countryName = CN
stateOrProvinceName = xinwang
organizationName = wang
commonName  = docker.benet.com
同样会提示输入一些内容,选择y就可以了!
查看nginx的证书
1
2
[iyunv@localhost ssl]# ls
nginx.crt  nginx.csr  nginx.key



8)安装,配置,运行nginx
(1) 添加组和用户
1
2
[iyunv@localhost ssl]# groupadd www
[iyunv@localhost ssl]# useradd -u 58 -g www  www



2)编译,安装nginx:
1
2
[iyunv@localhost nginx-1.11.2]# ./configure --user=www --group=www --prefix=/usr/local/nginx --with-pcre --with-http_stub_status_module --with-http_ssl_module --with-http_addition_module --with-http_realip_module --with-http_flv_module
[iyunv@localhost nginx-1.11.2]# make && make install



编辑vim /usr/local/nginx/conf/nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
user  www;
worker_processes  4;
  
events {
        worker_connections  4096;
}
  
http {
        include  mime.types;
        default_type  application/octet-stream;
        sendfile        on;
        keepalive_timeout  65;
        upstream registry {
                server  192.168.100.30:5000;
    }
  
        server {
                listen       443 ssl;
                server_name  docker.benet.com;
                ssl_certificate  /etc/pki/CA/ssl/nginx.crt;
                ssl_certificate_key  /etc/pki/CA/ssl/nginx.key;
                ssl_session_cache    shared:SSL:1m;
                ssl_session_timeout  5m;
                ssl_ciphers  HIGH:!aNULL:!MD5;
                ssl_prefer_server_ciphers  on;
                location  /  {
                        proxy_pass  http://registry;
                        client_max_body_size    3000m;
                        proxy_set_header  Host  $host;
                        proxy_set_header  X-Forward-For  $remote_addr;
                }
        }




相关选项含义:
ssl_session_cache会话缓存用于保存SSL会话,这些缓存在工作进程间共享,可以使用ssl_session_cache指令进行配置。1M缓存可以存放大约4000个会话。
ssl_session_timeout缓存超时,默认的缓存超时是5分钟。
ssl_ciphers  HIGH:!aNULL:!MD5使用高强度的加密算法
ssl_prefer_server_ciphers  on依赖SSLv3和TLSv1协议的服务器密码将优先于客户端密码。
1
2
3
4
5
6
[iyunv@localhost conf]# /usr/local/nginx/sbin/nginx  -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[iyunv@localhost conf]# /usr/local/nginx/sbin/nginx  
[iyunv@localhost conf]# netstat -anpt | grep 443
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      60205/nginx: master



2) 配置,运行Docker
(1) 停止docker
1
[iyunv@localhost conf]# systemctl stop docker



2)编辑/etc/sysconfig/docker文件,加上如下一行
1
2
3
DOCKER_OPTS="--insecure-registry docker.benet.com --tlsverify --tlscacert /etc/pki/CA/cacert.pem"
[iyunv@localhost conf]# mkdir -p /etc/docker/certs.d/docker.benet.com
[iyunv@localhostconf]#cp/etc/pki/CA/cacert.pem  /etc/docker/certs.d/docker.benet.com/ca-certificates.crt



4) 启动docker
1
[iyunv@localhost conf]# systemctl start docker



3)运行私有仓库容器
使用本地 载入registry 镜像来运行
1
2
3
[iyunv@localhost src]# docker load < registry.tar
root@localhost src]# docker images
docker.io/registry   latest              bca04f698ba8        19 months ago       422.8 MB



egistry 镜像来启动本地的私有仓库。用户可以通过指定参数来配置私有仓库位置。
1
[iyunv@localhost src]# mkdir -pv /opt/data/registrt



运行私有仓库容器
1
[iyunv@localhost src]# docker run -d -p 5000:5000 -v /opt/data/registrt/:/tmp/registrt docker.io/registry



可以通过 -v 参数来将镜像文件存放在本地的指定路径
-p(小写的)用于将容器的5000端口映射宿主机的5000端口
验证registry:
1
[iyunv@localhost src]# curl -i -k https://docker.benet.com



curl是通过url语法在命令行下上传或下载文件的工具软件,它支持http,https,ftp,ftps,telnet等多种协议,常被用来抓取网页和监控Web服务器状态
5)Docker客户端配置
1)编辑/etc/hosts,把docker.benet.com的ip地址添加进来
1
192.168.100.33 docker.benet.com



2)把docker registry服务器端的根证书追加到ca-certificates.crt文件里
先从docker registry服务器端把文件/etc/pki/CA/cacert.pem拷贝到本机,然后执行命令
1
2
[iyunv@localhost /]# scp root@192.168.100.33:/etc/pki/CA/cacert.pem ./
[iyunv@localhost /]# cat ./cacert.pem >> /etc/pki/tls/certs/ca-certificates.crt



在客户端输入浏览
1
2
[iyunv@localhost /]# curl -i -k https://docker.benet.com
"\"docker-registry server\""   成功



4) 使用私有registry步骤:
登录: docker logi
1
2
3
[iyunv@localhost /]# docker login https://docker.benet.com
Username: wang   
Password:



从Docker HUB 上拉取一个镜像测试,为基础镜像打个标签:
1
[iyunv@localhost /]# docker tag docker.io/centos docker.benet.com/centos:centos7



发布:上传镜像到本地私有仓库
1
[iyunv@localhost /]# docker push docker.benet.com/centos:centos7



看私有仓库是否有对应的镜像
1
2
[iyunv@localhost /]# yum -y install tree
[iyunv@localhost /]# tree /opt/data/registr/repositories



从私有仓库pull下来image,查看image
1
[iyunv@localhost /]# docker pull docker.benet.com/centos:centos7



查看私有仓库是否有对应的镜像
1
[iyunv@localhost /]# curl -k https://docker.benet.com/v1/search



运维网声明 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-403215-1-1.html 上篇帖子: docker容器从入门到实战 下篇帖子: Docker Supervisor
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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