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:
c url是通过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
|
在客户端输入浏览
4) 使用私有registry步骤: 登录: docker logi
从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
|
查看私有仓库是否有对应的镜像
|