我的環(huán)境相關(guān)設(shè)置如下
環(huán)境:centos7
IP地址:10.211.55.30
dockere版本:1.10.3
鏡像倉(cāng)庫(kù):v2
首先在10.211.55.30機(jī)器上下載registry鏡像
$ docker pull registry
也可以進(jìn)行鏡像導(dǎo)入的方法進(jìn)行離線的安裝??梢匀ノ业木W(wǎng)盤中下載:https://pan.baidu.com/s/1jHZlz2u
然后進(jìn)入Docker中進(jìn)行導(dǎo)入
$ docker load -i registry.tar
下載完之后我們通過該鏡像啟動(dòng)一個(gè)容器
$ docker run -d -p 5000:5000 registry
默認(rèn)情況下,會(huì)將倉(cāng)庫(kù)存放于容器內(nèi)的/tmp/registry目錄下,這樣如果容器被刪除,則存放于容器中的鏡像也會(huì)丟失,所以我們一般情況下會(huì)指定本地一個(gè)目錄掛載到容器內(nèi)的/tmp/registry下,我將/opt/data/registry目錄掛載到/tmp/registry目錄下,如果你本地沒有這個(gè)目錄需要新創(chuàng)建,同時(shí)需要給/opt/data/registry目錄擴(kuò)大權(quán)限
chmod +777 /opt/data/registry
此處有坑:默認(rèn)情況下是在容器內(nèi)的/tmp/registry目錄下,但是我的容器鏡像是存放在容器中的/var/lib/registry 這個(gè)位置。
我是搭建完畢之后,上傳一個(gè)鏡像之后然后使用 find / -name ***查到的位置
[root@server01 ~]# docker run -d -p 5000:5000 -v /opt/data/registry:/var/lib/registry registry 55c60589cb0e2d094d5371c4dd650127cfeae1b361477d50cfe48552e6308830
可以看到我們啟動(dòng)了一個(gè)容器,地址為:10.211.55.30:5000。
測(cè)試
接下來我們就要操作把一個(gè)本地鏡像push到私有倉(cāng)庫(kù)中。首先在10.211.55.30機(jī)器下pull一個(gè)比較小的鏡像來測(cè)試(此處使用的是busybox)
$ sudo docker pull busybox
接下來修改一下該鏡像的tag,鏡像的格式為 鏡像倉(cāng)庫(kù)IP:端口/鏡像名稱
$ sudo docker tag busybox 10.211.55.30:5000/busybox
接下來把打了tag的鏡像上傳到私有倉(cāng)庫(kù)。
$ sudo docker push 10.211.55.30:5000/busybox
可以看到push失敗,具體錯(cuò)誤如下:
因?yàn)镈ocker從1.3.X之后,與docker registry交互默認(rèn)使用的是https,然而此處搭建的私有倉(cāng)庫(kù)只提供http服務(wù),所以當(dāng)與私有倉(cāng)庫(kù)交互時(shí)就會(huì)報(bào)上面的錯(cuò)誤。為了解決這個(gè)問題需要在啟動(dòng)docker server時(shí)增加啟動(dòng)參數(shù)為默認(rèn)使用http訪問。修改docker啟動(dòng)配置文件(此處是修改10.211.55.30機(jī)器的配置)centos7下配置文件地址為:/usr/lib/systemd/system/docker.service,在其中增加–insecure-registry 10.211.55.30:5000如下所示:
[Unit] Description=Docker Application Container Engine Documentation=http://docs.docker.com After=network.target rhel-push-plugin.socket Wants=docker-storage-setup.service [Service] Type=notify NotifyAccess=all EnvironmentFile=-/etc/sysconfig/docker EnvironmentFile=-/etc/sysconfig/docker-storage EnvironmentFile=-/etc/sysconfig/docker-network Environment=GOTRACEBACK=crash ExecStart=/usr/bin/docker-current daemon / --exec-opt native.cgroupdriver=systemd / --insecure-registry=10.211.55.30:5000 / $OPTIONS / $DOCKER_STORAGE_OPTIONS / $DOCKER_NETWORK_OPTIONS / $ADD_REGISTRY / $BLOCK_REGISTRY / $INSECURE_REGISTRY LimitNOFILE=1048576 LimitNPROC=1048576 LimitCORE=infinity TimeoutStartSec=0 MountFlags=slave Restart=on-abnormal [Install] WantedBy=multi-user.target
修改完之后,重啟Docker服務(wù)。
$ restart docker
重啟完之后我們?cè)俅芜\(yùn)行推送命令,把本地鏡像推送到私有服務(wù)器上。
$ sudo docker push 10.211.55.30:5000/busybox
可以看到鏡像已經(jīng)push到私有倉(cāng)庫(kù)中去了。
進(jìn)行到這一步的時(shí)候也不一定能夠成功,使用journalctl -f 可以查看日志信息,通過日志信息可以查看到如下信息,關(guān)注標(biāo)紅的部分,顯示的是SELinux 的問題,我的處理方法是直接關(guān)閉SELinux
Jan 27 16:08:16 server01 docker-current[15241]: time="2017-01-27T08:08:16Z" level=error msg="response completed with error" err.code="blob unknown" err.detail=sha256:45a2e645736c4c66ef34acce2407ded21f7a9b231199d3b92d6c9776df264729 err.message="blob unknown to registry" go.version=go1.7.3 http.request.host="10.211.55.30:5000" http.request.id=a2dbff10-2937-4e9e-94f3-16275739ad61 http.request.method=HEAD http.request.remoteaddr="10.211.55.30:48256" http.request.uri="/v2/centos_20170127/blobs/sha256:45a2e645736c4c66ef34acce2407ded21f7a9b231199d3b92d6c9776df264729" http.request.useragent="docker/1.10.3 go/go1.6.3 git-commit/cb079f6-unsupported kernel/3.10.0-327.36.3.el7.x86_64 os/linux arch/amd64" http.response.contenttype="application/json; charset=utf-8" http.response.duration=1.4262ms http.response.status=404 http.response.written=157 instance.id=f9f97de9-15bc-41e3-9ec3-f1033e57a77e vars.digest="sha256:45a2e645736c4c66ef34acce2407ded21f7a9b231199d3b92d6c9776df264729" vars.name="centos_20170127" version=v2.6.0 Jan 27 16:08:16 server01 docker-current[15241]: 10.211.55.30 - - [27/Jan/2017:08:08:16 +0000] "HEAD /v2/centos_20170127/blobs/sha256:45a2e645736c4c66ef34acce2407ded21f7a9b231199d3b92d6c9776df264729 HTTP/1.1" 404 157 "" "docker/1.10.3 go/go1.6.3 git-commit/cb079f6-unsupported kernel/3.10.0-327.36.3.el7.x86_64 os/linux arch/amd64" Jan 27 16:08:16 server01 docker-current[15241]: time="2017-01-27T08:08:16Z" level=error msg="response completed with error" err.code=unknown err.detail="filesystem: mkdir /var/lib/registry/docker: permission denied" err.message="unknown error" go.version=go1.7.3 http.request.host="10.211.55.30:5000" http.request.id=158612a0-39f5-41f5-9985-c80db7da911f http.request.method=POST http.request.remoteaddr="10.211.55.30:48258" http.request.uri="/v2/centos_20170127/blobs/uploads/" http.request.useragent="docker/1.10.3 go/go1.6.3 git-commit/cb079f6-unsupported kernel/3.10.0-327.36.3.el7.x86_64 os/linux arch/amd64" http.response.contenttype="application/json; charset=utf-8" http.response.duration=1.671997ms http.response.status=500 http.response.written=164 instance.id=f9f97de9-15bc-41e3-9ec3-f1033e57a77e vars.name="centos_20170127" version=v2.6.0 Jan 27 16:08:16 server01 docker-current[15241]: 10.211.55.30 - - [27/Jan/2017:08:08:16 +0000] "POST /v2/centos_20170127/blobs/uploads/ HTTP/1.1" 500 164 "" "docker/1.10.3 go/go1.6.3 git-commit/cb079f6-unsupported kernel/3.10.0-327.36.3.el7.x86_64 os/linux arch/amd64" Jan 27 16:08:16 server01 docker-current[15241]: time="2017-01-27T16:08:16.115997771+08:00" level=error msg="Upload failed, retrying: Received unexpected HTTP status: 500 Internal Server Error" Jan 27 16:08:16 server01 setroubleshoot[5771]: failed to retrieve rpm info for /opt/data/registry Jan 27 16:08:16 server01 setroubleshoot[5771]: SELinux is preventing /bin/registry from write access on the directory /opt/data/registry. For complete SELinux messages. run sealert -l 748743d8-dd8a-4482-9771-94a403bccf18 Jan 27 16:08:16 server01 python[5771]: <strong>SELinux is preventing /bin/registry from write access on the directory /opt/data/registry.</strong> ***** Plugin catchall_labels (83.8 confidence) suggests ******************* If you want to allow registry to have write access on the registry directory Then you need to change the label on /opt/data/registry Do # semanage fcontext -a -t FILE_TYPE '/opt/data/registry' where FILE_TYPE is one of the following: cgroup_t, docker_var_lib_t, svirt_home_t, svirt_sandbox_file_t, virt_home_t. Then execute: restorecon -v '/opt/data/registry' ***** Plugin catchall (17.1 confidence) suggests ************************** If you believe that registry should be allowed write access on the registry directory by default. Then you should report this as a bug. You can generate a local policy module to allow this access. Do allow this access for now by executing: # grep registry /var/log/audit/audit.log | audit2allow -M mypol # semodule -i mypol.pp
關(guān)閉方法如下
查看SELinux狀態(tài):
1、/usr/sbin/sestatus -v ##如果SELinux status參數(shù)為enabled即為開啟狀態(tài) SELinux status: enabled 2、getenforce ##也可以用這個(gè)命令檢查
關(guān)閉SELinux:
1、臨時(shí)關(guān)閉(不用重啟機(jī)器):
setenforce 0 ##設(shè)置SELinux 成為permissive模式 setenforce 1 設(shè)置SELinux 成為enforcing模式
2、修改配置文件需要重啟機(jī)器:
修改/etc/selinux/config 文件
將SELINUX=enforcing改為SELINUX=disabled
重啟機(jī)器即可
接下來我們刪除本地鏡像,然后從私有倉(cāng)庫(kù)中pull下來該鏡像。
$ sudo docker pull 10.211.55.30:5000/busybox
到此就搭建好了Docker私有倉(cāng)庫(kù)。上面搭建的倉(cāng)庫(kù)是不需要認(rèn)證的。
管理倉(cāng)庫(kù)中的鏡像
查詢
在Private Registry2中查看或檢索Repository或images, 將不能用docker search,會(huì)報(bào)下邊的錯(cuò)誤
$ docker search 10.211.55.30:5000/busybox/ Error response from daemon: Unexpected status code 404
但通過v2版本的API,我們可以實(shí)現(xiàn)相同目的,必須按照IP:port/v2/_catalog格式:
[root@server01 ~]# curl http://10.211.55.30:5000/v2/_catalog {"repositories":["centos"]} [root@server01 ~]# curl http://10.211.55.30:5000/v2/centos/tags/list {"name":"centos","tags":["latest"]}
拉取鏡像如下
[root@server01 ~]# docker pull 10.211.55.30:5000/centos Using default tag: latest Trying to pull repository 10.211.55.30:5000/centos ... latest: Pulling from 10.211.55.30:5000/centos Digest: sha256:7dfffa13a2addc317ac3bdfbddbd4604ea629decea19c271481e5c45245b7612 Status: Downloaded newer image for 10.211.55.30:5000/centos:latest
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持VEVB武林網(wǎng)。
新聞熱點(diǎn)
疑難解答
圖片精選