您好,登錄后才能下訂單哦!
這篇文章主要介紹了Docker私有Registry如何在CentOS6.X下安裝,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
說明:
docker.yy.com
這是docker registry服務器的域名也就是你的公司docker私有服務器的主機地址,假定ip是192.168.2.114
;因為https的SSL證書不能用IP地址,我就隨便起了個名字。
registry
服務器作為上游服務器處理docker鏡像的最終上傳和下載,用的是官方的鏡像。
nginx 1.4.x
是一個用nginx作為反向代理服務器
yum -y install gcc make file && \ yum -y install tar pcre-devel pcre-staticopenssl openssl-devel httpd-tools
/etc/hosts
,把docker.yy.com
的ip地址添加進來,例如:192.168.2.114 docker.yy.com
先把
/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
刪除掉!
cd /etc/pki/CA/ openssl genrsa -out private/cakey.pem 2048
openssl req -new -x509 -key private/cakey.pem -out cacert.pem
輸出:
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) []:beijing Locality Name (eg, city) [Default City]:beijing Organization Name (eg, company) [Default Company Ltd]:youyuan Organizational Unit Name (eg, section) []: Common Name (eg, your name or your server's hostname) []:docker.yy.com Email Address []:
會提示輸入一些內容,因為是私有的,所以可以隨便輸入,最好記住能與后面保持一致,特別是"Common Name"。上面的自簽證書cacert.pem應該生成在/etc/pki/CA下。
mkdir -p /etc/nginx/ssl cd /etc/nginx/ssl openssl genrsa -out nginx.key 2048
我們的CA中心與要申請證書的服務器是同一個,否則應該是在另一臺需要用到證書的服務器上生成。
openssl req -new -key nginx.key -out nginx.csr
輸出:
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) []:beijing Locality Name (eg, city) [Default City]:beijing Organization Name (eg, company) [Default Company Ltd]:youyuan Organizational Unit Name (eg, section) []: Common Name (eg, your name or your server's hostname) []:docker.yy.com Email Address []: Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []:
同樣會提示輸入一些內容,Commone Name一定要是你要授予證書的服務器域名或主機名,challenge password不填。
touch /etc/pki/CA/index.txt touch /etc/pki/CA/serial echo 00 > /etc/pki/CA/serial openssl ca -in nginx.csr -out nginx.crt
輸出:
Using configuration from /etc/pki/tls/openssl.cnf Check that the request matches the signature Signature ok Certificate Details: Serial Number: 0 (0x0) Validity Not Before: Dec 9 09:59:20 2014 GMT Not After : Dec 9 09:59:20 2015 GMT Subject: countryName = CN stateOrProvinceName = beijing organizationName = youyuan commonName = docker.yy.com X509v3 extensions: X509v3 Basic Constraints: CA:FALSE Netscape Comment: OpenSSL Generated Certificate X509v3 Subject Key Identifier: 5D:6B:02:FF:9E:F8:EA:1B:73:19:47:39:4F:88:93:9F:E7:AC:A5:66 X509v3 Authority Key Identifier: keyid:46:DC:F1:A5:6F:39:EC:6E:77:03:3B:C4:34:03:7E:B8:0A:ED:99:41 Certificate is to be certified until Dec 9 09:59:20 2015 GMT (365 days) Sign the certificate? [y/n]:y 1 out of 1 certificate requests certified, commit? [y/n]y Write out database with 1 new entries Data Base Updated
同樣會提示輸入一些內容,選擇
y
就可以了!
groupadd www -g 58 useradd -u 58 -g www www
cd /tmp wget http://nginx.org/download/nginx-1.4.6.tar.gz cp ./nginx-1.4.6.tar.gz /tmp/
tar zxvf ./nginx-1.4.6.tar.gz cd ./nginx-1.4.6 && \ ./configure --user=www --group=www --prefix=/opt/nginx \ --with-pcre \ --with-http_stub_status_module \ --with-http_ssl_module \ --with-http_addition_module \ --with-http_realip_module \ --with-http_flv_module && \ make && \ make install cd /tmp rm -rf /tmp/nginx-1.4.6/ rm /tmp/nginx-1.4.6.tar.gz
htpasswd -cb /opt/nginx/conf/.htpasswd ${USER} ${PASSWORD}
/opt/nginx/conf/nginx.conf
文件#daemon off; # 使用的用戶和組 user www www; # 指定工作進程數(一般等于CPU總核數) worker_processes auto; # 指定錯誤日志的存放路徑,錯誤日志記錄級別選項為:[debug | info | notic | warn | error | crit] error_log /var/log/nginx_error.log error; #指定pid存放的路徑 #pid logs/nginx.pid; # 指定文件描述符數量 worker_rlimit_nofile 51200; events { # 使用的網絡I/O模型,Linux推薦epoll;FreeBSD推薦kqueue use epoll; # 允許的最大連接數 worker_connections 51200; multi_accept on; } http { include mime.types; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$upstream_addr"'; access_log /var/log/nginx_access.log main; # 服務器名稱哈希表的桶大小,該默認值取決于CPU緩存 server_names_hash_bucket_size 128; # 客戶端請求的Header頭緩沖區大小 client_header_buffer_size 32k; large_client_header_buffers 4 32k; # 啟用sendfile()函數 sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; upstream registry { server 127.0.0.1:5000; } server { listen 443; server_name 192.168.2.114; ssl on; ssl_certificate /etc/nginx/ssl/nginx.crt; ssl_certificate_key /etc/nginx/ssl/nginx.key; client_max_body_size 0; # disable any limits to avoid HTTP 413 for large image uploads # required to avoid HTTP 411: see Issue #1486 (https://github.com/docker/docker/issues/1486) chunked_transfer_encoding on; location / { auth_basic "registry"; auth_basic_user_file /opt/nginx/conf/.htpasswd; root html; index index.html index.htm; proxy_pass http://registry; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Authorization ""; client_body_buffer_size 128k; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 90; proxy_buffer_size 8k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; #如果系統很忙的時候可以申請更大的proxy_buffers 官方推薦*2 proxy_temp_file_write_size 64k; #proxy緩存臨時文件的大小 } location /_ping { auth_basic off; proxy_pass http://registry; } location /v1/_ping { auth_basic off; proxy_pass http://registry; } } }
/opt/nginx/sbin/nginx -t
輸出:
nginx: the configuration file /opt/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /opt/nginx/conf/nginx.conf test is successful
/opt/nginx/sbin/nginx
ps -ef | grep -i 'nginx'
如下輸出就表明nginx一切正常!
root 27133 1 0 18:58 ? 00:00:00 nginx: master process /opt/nginx/sbin/nginx www 27134 27133 0 18:58 ? 00:00:00 nginx: worker process www 27135 27133 0 18:58 ? 00:00:00 nginx: worker process www 27136 27133 0 18:58 ? 00:00:00 nginx: worker process www 27137 27133 0 18:58 ? 00:00:00 nginx: worker process www 27138 27133 0 18:58 ? 00:00:00 nginx: worker process www 27139 27133 0 18:58 ? 00:00:00 nginx: worker process www 27140 27133 0 18:58 ? 00:00:00 nginx: worker process www 27141 27133 0 18:58 ? 00:00:00 nginx: worker process www 27142 27133 0 18:58 ? 00:00:00 nginx: worker process www 27143 27133 0 18:58 ? 00:00:00 nginx: worker process www 27144 27133 0 18:58 ? 00:00:00 nginx: worker process www 27145 27133 0 18:58 ? 00:00:00 nginx: worker process www 27146 27133 0 18:58 ? 00:00:00 nginx: worker process www 27147 27133 0 18:58 ? 00:00:00 nginx: worker process www 27148 27133 0 18:58 ? 00:00:00 nginx: worker process www 27149 27133 0 18:58 ? 00:00:00 nginx: worker process www 27150 27133 0 18:58 ? 00:00:00 nginx: worker process www 27151 27133 0 18:58 ? 00:00:00 nginx: worker process www 27152 27133 0 18:58 ? 00:00:00 nginx: worker process www 27153 27133 0 18:58 ? 00:00:00 nginx: worker process www 27154 27133 0 18:58 ? 00:00:00 nginx: worker process www 27155 27133 0 18:58 ? 00:00:00 nginx: worker process www 27156 27133 0 18:58 ? 00:00:00 nginx: worker process www 27157 27133 0 18:58 ? 00:00:00 nginx: worker process root 27160 42863 0 18:58 pts/0 00:00:00 grep -i nginx
service docker stop
/etc/sysconfig/docker
文件,加上如下一行DOCKER_OPTS="--insecure-registry docker.yy.com --tlsverify --tlscacert /etc/pki/CA/cacert.pem"
/etc/docker/certs.d/docker.yy.com/
目錄下mkdir -p /etc/docker/certs.d/docker.yy.com/ cp /etc/pki/CA/cacert.pem /etc/docker/certs.d/docker.yy.com/ca-certificates.crt
service docker start
registry
imagedocker pull registry
mkdir -p /opt/registry docker run -d -e STORAGE_PATH=/registry -v /opt/registry:/registry -p 127.0.0.1:5000:5000 --name registry registry
命令稍加解釋一下:
-p 127.0.0.1:5000:5000
registry 作為上游服務器,這個 5000 端口可以不用映射出來,因為所有的外部訪問都是通過前端的nginx來提供,nginx 可以在私有網絡訪問 registry 。
用瀏覽器輸入:
https://docker.yy.com
或者:curl -i -k https://abc:123@docker.yy.com
服務端的配置就到此完成!
/etc/hosts
,把docker.yy.com
的ip地址添加進來,例如:192.168.2.114 docker.yy.com
先從docker registry服務器端把文件/etc/pki/CA/cacert.pem
拷貝到本機,然后執行命令:
cat ./cacert.pem >> /etc/pki/tls/certs/ca-certificates.crt
docker.yy.com
下的registry:用瀏覽器輸入:
https://docker.yy.com
或者:curl -i -k https://abc:123@docker.yy.com
登錄: docker login -u abc -p 123 -e "test@gmail.com" https://docker.yy.com
給container起另外一個名字: docker tag centos:centos6 docker.yy.com/centos:centos6
發布: docker push docker.yy.com/centos:centos6
docker push centos:centos6
執行docker images
輸出:
root@pts/0 # docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE centos centos6 25c5298b1a36 8 days ago 215.8 MB
docker tag 25c5298b1a36 docker.yy.com/centos:centos6
docker push docker.yy.com/centos:centos6
docker images
輸出:
root@pts/0 # docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE centos centos6 25c5298b1a36 8 days ago 215.8 MB docker.yy.com/centos centos6 25c5298b1a36 8 days ago 215.8 MB
docker pull docker.yy.com/centos:centos6
docker images
輸出:
root@pts/0 # docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE docker.yy.com/centos centos6 25c5298b1a36 8 days ago 215.8 MB
/etc/sysconfig/docker
文件在DOCKER_OPTS
里添加-H tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock
,例如:
DOCKER_OPTS="-H tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock --insecure-registry docker.yy.com --tlsverify --tlscacert /etc/pki/CA/cacert.pem --registry-mirror=http://d194d5cb.m.daocloud.io"
docker run -it -d --name shipyard-rethinkdb-data --entrypoint /bin/bash shipyard/rethinkdb -l
docker run -it -P -d --name shipyard-rethinkdb --volumes-from shipyard-rethinkdb-data shipyard/rethinkdb
If your server is directly accessible on Internet,
please note your RethinkDB installation may publicly listen to
ports49153
(local instance),49154
(cluster) and49155
(web interface) and so accessible to all.
docker run -it -p 8080:8080 -d --name shipyard --link shipyard-rethinkdb:rethinkdb shipyard/shipyard
Shipyard will create a default user account with the username
admin
and the passwordshipyard
.
You should then be able to open a browser tohttp://<your-host-ip>:8080
and see the Shipyard login.
server端可以login到官方的Docker Hub,可以pull,push官方和私有倉庫!
client端只能操作搭設好的私有倉庫!
私有倉庫不能search!
所有的build,pull,push操作只能在私有倉庫的server端操作,降低企業風險!
docker login
到官方的https://index.docker.io/v1/
網站,出現x509: certificate signed by unknown authority
錯誤時重命名根證書!
mv /etc/pki/tls/certs/ca-certificates.crt /etc/pki/tls/certs/ca-certificates.crt.bak
重啟docker服務!service docker restart
!
感謝你能夠認真閱讀完這篇文章,希望小編分享的“Docker私有Registry如何在CentOS6.X下安裝”這篇文章對大家有幫助,同時也希望大家多多支持億速云,關注億速云行業資訊頻道,更多相關知識等著你來學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。