安装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/

  1. 安装和启动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

这就得到了一个叫localhost:5000的registry

可以通过修改/etc/docker-distribution/registry/config.yml,来改变registry服务的行为

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上,发生的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

  1. 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端,关于registry使用的选择:

Docker Project本身,不支持修改默认registry (Docker Hub Registry),也不支持Block任何registry。但是在各种Linux发型版或Atomic版本中,后续加入了这些特性支持:

  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>’

注:docker-registry 无法启动,因为过时了,现在是docker-distribution
docker-registry is obsoleted by docker-distribution, trying to install docker-distribution-2.6.2-2.git48294d9.el7.x86_64 instead

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值