麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 基礎常識 > 正文

搭建Docker私有倉庫的詳細教程

2020-10-21 21:51:32
字體:
來源:轉載
供稿:網友

1.Docker registry 說明
本文記錄的個人完整搭建docker registry操作過程,官方雖然提供了Docker Hub作為一個公開的集中倉庫,但是天朝的網絡可想而知,第一次pull一個鏡像不是失敗就是時間很長,為了解決這個問題需要創建一個私有的倉庫在本地pull 本地push。我使用的docker版本是:1.5.0

2、安裝docker-registry


復制代碼
代碼如下:
docker run -d -e SETTINGS_FLAVOR=dev -e STORAGE_PATH=/tmp/registry -v /alidata/registry:/tmp/registry -p 5000:5000 registry

# 如果本地沒有下載過docker-registry,則首次會pull registry 運行時會映射路徑和端口,以后就可以從/data/registry下找到私有倉庫

3、客戶端上的操作
#從本地倉庫上獲取有哪些鏡像
 

復制代碼
代碼如下:
curl -X GET http://registry.wpython.com:5000/v1/search

curl http://registry.wpython.com:5000/v1/search
{"num_results": 1, "query": "", "results": [{"description": "", "name": "library/centos6"}]}

# 拉取到本地
 

復制代碼
代碼如下:
docker pull library/centos6

# tag 一個鏡像
 

復制代碼
代碼如下:
docker tag 8552ea9a16f9 registry.wpython.com:5000/centos6_x86_64.mini

# 將新的docker images push 到本地倉庫
 

復制代碼
代碼如下:
docker push registry.wpython.com:5000/centos6_x86_64.mini

4、加入nginx認證
Docker 啟動監聽端口后,使用的是 http,可以遠程來管理 Docker 主機。
這樣的場景存在弊端,API 層面是沒有提供用戶驗證、Token 之類身份驗證功能,任何人都可以通過地址加端口來控制 Docker 主機,為了避免這樣的情況發生,Docker 官方也支持 https 方式,不過需要我們自己來生成證書。
新版本的docker 也強制必須使用https否則會報錯

# 安裝nginx過程略
創建一個登陸用戶(如果沒有htpasswd命令 請安裝httpd-tools這個包)

 

復制代碼
代碼如下:
htpasswd -c /alidata/server/nginx/docker-registry.htpasswd admin
New password:
Re-type new password:
Adding password for user admin

# 生成根密鑰
 

復制代碼
代碼如下:
cd /etc/pki/CA/
openssl genrsa -out private/cakey.pem 2048

# 生成根證書
 

復制代碼
代碼如下:
openssl req -new -x509 -key private/cakey.pem -out cacert.pem

Country Name (2 letter code) [AU]:CN
State or Province Name (full name) [Some-State]:Brijing
Locality Name (eg, city) []:Chaoyang
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:registry.wpython.com
Email Address []:

# 為nginx服務器生成ssl密鑰
 

復制代碼
代碼如下:
cd /alidata/server/nginx/ssl
openssl genrsa -out nginx.key 2048

# 為nginx生成的證書簽署請求
 

復制代碼
代碼如下:
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) [AU]:CN
State or Province Name (full name) [Some-State]:Beijing
Locality Name (eg, city) []:Chaoyang
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:registry.wpython.com
Email Address []:
 
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

# 私有CA根據請求來簽發證書
 

復制代碼
代碼如下:
openssl ca -in nginx.csr -out nginx.crt

 
 
# 如果報如下錯誤:
Using configuration from /usr/local/ssl/openssl.cnf
/etc/pki/CA/index.txt: No such file or directory
unable to open '/etc/pki/CA/index.txt'
140137408210600:error:02001002:system library:fopen:No such file or directory:bss_file.c:398:fopen('/etc/pki/CA/index.txt','r')
140137408210600:error:20074002:BIO routines:FILE_CTRL:system lib:bss_file.c:400:
 
# 執行以下命令

復制代碼
代碼如下:
cd /etc/pki/CA/
mkdir newcerts
touch index.txt
touch serial
echo 01 > serial
cd -

openssl ca -in nginx.csr -out nginx.crt

 
Using configuration from /usr/local/ssl/openssl.cnf
Check that the request matches the signature
Signature ok
Certificate Details:
        Serial Number: 1 (0x1)
        Validity
            Not Before: May 12 04:15:08 2015 GMT
            Not After : May 11 04:15:08 2016 GMT
        Subject:
            countryName               = CN
            stateOrProvinceName       = Beijing
            organizationName          = Internet Widgits Pty Ltd
            commonName                = registry.wpython.com
            emailAddress              = [email protected]
        X509v3 extensions:
            X509v3 Basic Constraints:
                CA:FALSE
            Netscape Comment:
                OpenSSL Generated Certificate
            X509v3 Subject Key Identifier:
                B5:20:C7:47:26:D9:26:54:12:F7:36:7E:4E:3A:F0:D9:0E:2C:F7:BD
            X509v3 Authority Key Identifier:
                keyid:93:F7:86:72:1B:2B:24:CD:AF:24:EF:53:F4:E1:FA:EC:E7:70:1A:90
 
Certificate is to be certified until May 11 04:15:08 2016 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

# 發現根證書
 


復制代碼
代碼如下:
# cp /etc/pki/tls/certs/ca-bundle.crt{,.bak} 備份以防出錯
# cat /etc/pki/CA/cacert.pem >> /etc/pki/tls/certs/ca-bundle.crt

# 創建nginx配置文件
 

復制代碼
代碼如下:
# vi /alidata/server/nginx/conf/vhosts/www.wpython.com.conf
upstream docker-registry {

server localhost:5000;
}

server {
listen 8080;
server_name registry.wpython.com;

# enabled ssl
ssl on;
ssl_certificate /alidata/server/nginx/ssl/nginx.crt;
ssl_certificate_key /alidata/server/nginx/ssl/nginx.key;

proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
client_max_body_size 0;
chunked_transfer_encoding on;

location / {

auth_basic "Restricted";
auth_basic_user_file docker-registry.htpasswd;
proxy_pass http://docker-registry;

}

location /_ping {

auth_basic off;
proxy_pass http://docker-registry;

}

location /v1/_ping {
auth_basic off;
proxy_pass http://docker-registry;
}
}

# 完成測試

 

復制代碼
代碼如下:
# docker login https://registry.wpython.com:8080
Username: admin
Password:
Email: [email protected]
Login Succeeded

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 亚洲一二区精品 | 免费的性生活视频 | 一区二区三高清 | 精品国产一区二区三区天美传媒 | 91快色| 性欧美暴力猛交69hd | 亚洲精品一区二区三区在线看 | 依人在线视频 | 午夜精品小视频 | 在线播放av片| 国产成人精品日本亚洲语音 | 依依成人综合 | 草久影院| 啊~用cao嗯力cao烂我视频 | 一级做a爱片久久毛片a高清 | 美女被免费网站在线软件 | 免费一级在线 | 精品视频一区二区三区四区 | 热久久成人 | 亚洲草逼视频 | 羞羞的小视频 | 免费在线中文字幕 | 久久精品无码一区二区三区 | 国产成人综合在线观看 | 亚洲性生活免费视频 | 精品久久久久久久久久中出 | 国产精品视频一区二区三区四区五区 | 亚洲午夜天堂吃瓜在线 | 欧美一区二区三区不卡免费观看 | 国产精品99精品 | 国产精品一区免费在线观看 | 91九色福利| 叶子楣成人爽a毛片免费啪啪 | 久久精品国产99久久6动漫亮点 | 91久久精品一区二区 | japanese末成年free | 日本最新免费二区三区 | 免费观看国产视频 | av在线等| 亚洲最新无码中文字幕久久 | 成人18在线 |