2018-09-01 <Docker容器> 第三章 搭建私有的docker registry

搭建和運行Docker Register兩類方式:

1. 對于 Redhat / centos/ fedora :安裝docker-distribution軟件(Package docker-registry is obsoleted by docker-distribution)

2. 對于ubuntu/Atomic: 運行registry的容器景象


docker-registry安裝軟件的方式 (Centos)

一,軟件的配置:

1. registry軟件端口:5000

如果registry(鏡像存儲端)和docker(景象使用端)不在一個server上,需要開端口

2.registry景象存儲位置:

/var/lib/registry/

3. 安裝和啟動registry(同一個server)

step1. install registry

[root@k8s-ubuntu-mini ~]# yum install docker-registry

Loaded plugins: fastestmirror

Loading mirror speeds from cached hostfile

* base: mirror.hosting90.cz

* extras: ftp.sh.cvut.cz

* updates: ftp.sh.cvut.cz

base? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | 3.6 kB? 00:00:00

extras? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | 3.4 kB? 00:00:00

updates? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | 3.4 kB? 00:00:00

(1/2): extras/7/x86_64/primary_db? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | 187 kB? 00:00:00

(2/2): updates/7/x86_64/primary_db? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | 5.2 MB? 00:00:02

Package docker-registry is obsoleted by docker-distribution, trying to install docker-distribution-2.6.2-2.git48294d9.el7.x86_64 instead

...

[root@k8s-ubuntu-mini ~]# rpm -ql docker-distribution | more

/etc/docker-distribution/registry/config.yml

/usr/bin/registry

/usr/lib/systemd/system/docker-distribution.service

/usr/share/doc/docker-distribution-2.6.2

/usr/share/doc/docker-distribution-2.6.2/AUTHORS

/usr/share/doc/docker-distribution-2.6.2/CONTRIBUTING.md

/usr/share/doc/docker-distribution-2.6.2/LICENSE

/usr/share/doc/docker-distribution-2.6.2/MAINTAINERS

/usr/share/doc/docker-distribution-2.6.2/README.md

/var/lib/registry

[root@k8s-ubuntu-mini ~]#

step2. start registry

[root@k8s-ubuntu-mini ~]# systemctl start docker-distribution

[root@k8s-ubuntu-mini ~]# systemctl enable docker-distribution

Created symlink from /etc/systemd/system/multi-user.target.wants/docker-distribution.service to /usr/lib/systemd/system/docker-distribution.service.

[root@k8s-ubuntu-mini ~]# ps -ef | grep -i distribution

root? ? 10532? ? 1? 0 09:21 ?? ? ? ? 00:00:01 /usr/bin/registry serve /etc/docker-distribution/registry/config.yml

這就得到了一個叫l(wèi)ocalhost:5000的registry

可以通過修改/etc/docker-distribution/registry/config.yml,來改變registry服務(wù)的行為

step3. test registry

-- 先下載一個測試鏡像(從默認的Ducker Hub Registry :docker.io中, 搜索名字里有hello-world 的景象, 然后用全路徑下載。 只是search和pull,無須docker login)

[root@k8s-ubuntu-mini ~]# docker search hello-world

INDEX? ? ? NAME? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? DESCRIPTION? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? STARS? ? OFFICIAL? AUTOMATED

docker.io? docker.io/hello-world? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Hello World! (an example of minimal Docker...? 642? ? ? [OK]

docker.io? docker.io/kitematic/hello-world-nginx? ? ? ? ? ? ? ? A light-weight nginx container that demons...? 108

...

[root@k8s-ubuntu-mini ~]# docker pull docker.io/hello-world

Using default tag: latest

Trying to pull repository docker.io/library/hello-world ...

latest: Pulling from docker.io/library/hello-world

9db2ca6ccae0: Pull complete

Digest: sha256:4b8ff392a12ed9ea17784bd3c9a8b1fa3299cac44aca35a85c90c5e3c7afacdc

Status: Downloaded newer image for docker.io/hello-world:latest

[root@k8s-ubuntu-mini ~]#

[root@k8s-ubuntu-mini ~]# docker image list

REPOSITORY? ? ? ? ? ? ? TAG? ? ? ? ? ? ? ? IMAGE ID? ? ? ? ? ? CREATED? ? ? ? ? ? SIZE

docker.io/hello-world? latest? ? ? ? ? ? ? 2cb0d9787c4d? ? ? ? 7 weeks ago? ? ? ? 1.85 kB

image存放在mysql里,配置文件在/etc/lib/docker/image/下


-- 把下載image tag一個標簽,然后push到剛搭建的registry里 (這是在registry server上,發(fā)生的docker端對registry端的操作

[root@k8s-ubuntu-mini ~]# docker tag hello-world:latest localhost:5000/hello-me:latest

[root@k8s-ubuntu-mini ~]# docker push localhost:5000/hello-me:latest

The push refers to a repository [localhost:5000/hello-me]

ee83fc5847cb: Pushed

latest: digest: sha256:aca41a608e5eb015f1ec6755f490f3be26b48010b178e78c00eac21ffbe246f1 size: 524

[root@k8s-ubuntu-mini ~]#

-- 清理Docker Hub Registry下載的原鏡像

[root@k8s-ubuntu-mini ~]# docker rmi hello-world

Untagged: hello-world:latest

Untagged: docker.io/hello-world@sha256:4b8ff392a12ed9ea17784bd3c9a8b1fa3299cac44aca35a85c90c5e3c7afacdc

Untagged: localhost:5000/hello-me@sha256:aca41a608e5eb015f1ec6755f490f3be26b48010b178e78c00eac21ffbe246f1


4. docker side, 使用新建的registry

* 除了本地registry,其余可用的、blocked的registry在編輯/etc/containers/registries.conf里定義。

拉取鏡像

[root@k8s-ubuntu-mini ~]# docker pull localhost:5000/hello-me:latest

Trying to pull repository localhost:5000/hello-me ...

latest: Pulling from localhost:5000/hello-me

Digest: sha256:aca41a608e5eb015f1ec6755f490f3be26b48010b178e78c00eac21ffbe246f1

Status: Image is up to date for localhost:5000/hello-me:latest

[root@k8s-ubuntu-mini ~]#

[root@k8s-ubuntu-mini ~]# docker images

REPOSITORY? ? ? ? ? ? ? ? TAG? ? ? ? ? ? ? ? IMAGE ID? ? ? ? ? ? CREATED? ? ? ? ? ? SIZE

localhost:5000/hello-me? latest? ? ? ? ? ? ? 2cb0d9787c4d? ? ? ? 7 weeks ago? ? ? ? 1.85 kB

[root@k8s-ubuntu-mini ~]#

到這能看到,這個image的下載來源變成了剛剛建的registry

二、Docker鏡像的命名空間和registry使用的選擇

命名空間,世界上每個image有唯一的名字。

在Docker端,關(guān)于registry使用的選擇:

Docker Project本身,不支持修改默認registry (Docker Hub Registry),也不支持Block任何registry。但是在各種Linux發(fā)型版或Atomic版本中,后續(xù)加入了這些特性支持:

1. Redhat: /etc/sysconfig/docker --

(1)添加registry,增加下面一行:

ADD_REGISTRY='--add-registry <registry_name>'

? ps: 當添加一個使用https通訊的registry,又沒有registry提供的證書,那么還要多加這一行

INSECURE_REGISTRY=‘--insecure-registry’

(2)修改默認registry,只需要上面這一行放在docker.io前面

(3)停用某個registry,增加下面一行:

BLOCK_REGSTRY='--block-registry <registry_name>'

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容