-----------------------------------------node
1、版本說明docker
2、Server配置(registry 倉庫)bash
製做簽名dom
安裝registrycurl
製做tagtcp
上傳測試ide
複製證書到Client測試
3、Client配置ui
添加hosts記錄url
下載測試
搜索測試
安裝測試
-----------------------------------------
1、版本說明
操做系統版本:CentOS Linux release 7.3.1611
Docker版本:17.06.0-ce
2、Server配置(registry 倉庫)
1.製做簽名
# mkdir /certs # openssl req -newkey rsa:2048 -nodes -sha256 -keyout /certs/domain.key -x509 -days 365 -out /certs/domain.crt Generating a 2048 bit RSA private key .........+++ ......+++ writing new private key to '/certs/domain.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) []:beijing Locality Name (eg, city) [Default City]:beijing Organization Name (eg, company) [Default Company Ltd]:foo Organizational Unit Name (eg, section) []:bar Common Name (eg, your name or your server's hostname) []:mydocker.com Email Address []:360529415@qq.com
# cd /certs/ //查看證書 [root@host certs]# ll total 8 -rw-r--r-- 1 root root 1424 Oct 12 19:30 domain.crt -rw-r--r-- 1 root root 1704 Oct 12 19:30 domain.key
添加hosts記錄
# vi /etc/hosts 10.246.106.231 mydocker.com
2.安裝registry
# docker p_w_picpaths REPOSITORY TAG IMAGE ID CREATED SIZE httpd latest 52c70f4c9842 2 days ago 177MB registry latest 28525f9a6e46 3 weeks ago 33.2MB busybox latest 54511612f1c4 4 weeks ago 1.13MB # docker run -d -p 5000:5000 --restart=always --name registry \ -v /data01:/var/lib/registry \ -v /certs:/certs \ -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/domain.crt \ -e REGISTRY_HTTP_TLS_KEY=/certs/domain.key \ registry bda33d3805bf235abb4e20f6bff7e2434701a5450aa1f42df26bfac68c4d934a
3.製做tag
# docker tag prom/node-exporter:latest mydocker.com:5000/nuo/prom/node-exporter:latest # docker p_w_picpaths REPOSITORY TAG IMAGE ID CREATED SIZE prom/node-exporter latest 12d51ffa2b22 6 days ago 22.8MB mydocker.com:5000/nuo/prom/node-exporter latest 12d51ffa2b22 6 days ago 22.8MB registry latest 28525f9a6e46 3 weeks ago 33.2MB busybox latest 54511612f1c4 4 weeks ago 1.13MB
4.上傳測試
# docker push mydocker.com:5000/nuo/prom/node-exporter The push refers to a repository [mydocker.com:5000/nuo/prom/node-exporter] 5f70bf18a086: Pushed 1c7f6350717e: Pushed a349adf62fe1: Pushed c7300f623e77: Pushed latest: digest: sha256:57d9b335b593e4d0da1477d7c5c05f23d9c3dc6023b3e733deb627076d4596ed size: 1979 # docker rmi mydocker.com:5000/nuo/prom/node-exporter:latest //刪除本地製做的鏡像 Untagged: mydocker.com:5000/nuo/prom/node-exporter:latest Untagged: mydocker.com:5000/nuo/prom/node-exporter@sha256:57d9b335b593e4d0da1477d7c5c05f23d9c3dc6023b3e733deb627076d4596ed
5.複製證書到Client
# scp /certs/domain.crt 10.246.147.20:/etc/docker/certs.d/mydocker.com\:5000/ca.crt //須要提早在Client主機/etc/docker/內新建certs.d/mydocker.com:5000目錄
3、Client配置
1.添加hosts記錄
# cat /etc/hosts 10.246.106.231 mydocker.com
2.下載測試
# docker pull mydocker.com:5000/nuo/httpd Using default tag: latest latest: Pulling from nuo/httpd 85b1f47fba49: Pull complete 3dee1a596b5f: Pull complete 86144720cb98: Pull complete 23273e61b31a: Pull complete 011f98a84808: Pull complete 71f27eec7416: Pull complete b87d74086bb4: Pull complete Digest: sha256:88053f79c62d0351b4dcab32ebdce904b707ce0f8e549b2f7c1bd5b2634b15e5 Status: Downloaded newer p_w_picpath for mydocker.com:5000/nuo/httpd:latest # docker p_w_picpaths REPOSITORY TAG IMAGE ID CREATED SIZE mydocker.com:5000/nuo/httpd latest 52c70f4c9842 2 days ago 177MB
3.搜索測試
因爲是搭建的私有倉庫,docker search命令再也不適用
# cd /etc/docker/certs.d/mydocker.com\:5000/ # curl --cacert ca.crt --basic https://mydocker.com:5000/v2/_catalog {"repositories":["nuo/httpd"]} # curl --cacert ca.crt --basic https://mydocker.com:5000/v2/nuo/httpd/tags/list {"name":"nuo/httpd","tags":["latest"]}
4.安裝測試
# docker run -d -p 80:80 --name=httpd mydocker.com:5000/nuo/httpd c7fe9bd3679244e8ef6643ba62799882f8325fffe68e3542ed0d344acc94b3de # docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c7fe9bd36792 mydocker.com:5000/nuo/httpd "httpd-foreground" 4 seconds ago Up 3 seconds 0.0.0.0:80->80/tcp httpd