Docker Registry-源码安装

确认Golang环境安装成功,并配置$GOPATH环境变量,例如/go。
go version go1.9.2 linux/amd64

安装

1、获取源码:

wang@wang:~/go/src/github.com/docker$ git clone https://github.com/docker/distribution.git
输出如下:
Cloning into 'distribution'...
remote: Enumerating objects: 29, done.
remote: Counting objects: 100% (29/29), done.
remote: Compressing objects: 100% (26/26), done.
remote: Total 19770 (delta 5), reused 16 (delta 3), pack-reused 19741
Receiving objects: 100% (19770/19770), 12.77 MiB | 348.00 KiB/s, done.
Resolving deltas: 100% (10665/10665), done.
Checking connectivity... done.
Checking out files: 100% (1188/1188), done.

2、将自带的模板配置文件复制到/etc/docker/registry/路径下,创建存储目录/var/lib/registry:

wang@wang:~/go/src/github.com/docker/distribution$ sudo cp cmd/registry/config-dev.yml /etc/docker/registry/config.yml

wang@wang:~$ sudo mkdir -p /var/lib/registry

3、编译:

wang@wang:~/go/src/github.com/docker/distribution$ make PREFIX=/go clean binaries
输出如下:
+ clean
+ bin/registry
+ bin/digest
+ bin/registry-api-descriptor-template
+ binaries

wang@wang:~/go/src/github.com/docker/distribution/bin$ ./registry -v
./registry github.com/docker/distribution v2.7.0

4、启动:

wang@wang:~/go/src/github.com/docker/distribution/bin$ ./registry serve /etc/docker/registry/config.yml

5、访问本地5000端口,看到返回“200 OK”,则说明成功了。

wang@wang:~$ curl -i 127.0.0.1:5000/v2/
输出:
HTTP/1.1 200 OK
Content-Length: 2
Content-Type: application/json; charset=utf-8
Docker-Distribution-Api-Version: registry/2.0
X-Content-Type-Options: nosniff
Date: Thu, 06 Dec 2018 09:53:49 GMT

{}

测试

1、启动

root@wang:/home/wang/go/src/github.com/docker/distribution/bin# ./registry serve /etc/docker/registry/config.yml
打印:
INFO[0000] debug server listening :5001                 
WARN[0000] No HTTP secret provided - generated random secret. This may cause problems with uploads if multiple registries are behind a load-balancer. To provide a shared secret, fill in http.secret in the configuration file or set the REGISTRY_HTTP_SECRET environment variable.  environment=development go.version=go1.9.2 instance.id=584580dc-8ae9-4a2e-8446-0eac6947c407 service=registry version=v2.7.0
INFO[0000] endpoint local-5003 disabled, skipping        environment=development go.version=go1.9.2 instance.id=584580dc-8ae9-4a2e-8446-0eac6947c407 service=registry version=v2.7.0
INFO[0000] endpoint local-8083 disabled, skipping        environment=development go.version=go1.9.2 instance.id=584580dc-8ae9-4a2e-8446-0eac6947c407 service=registry version=v2.7.0
INFO[0000] using redis blob descriptor cache             environment=development go.version=go1.9.2 instance.id=584580dc-8ae9-4a2e-8446-0eac6947c407 service=registry version=v2.7.0
INFO[0000] providing prometheus metrics on /metrics     
INFO[0000] listening on [::]:5000 

(我这里不用root权限启动的话,在把镜像push到Registry的时候会提示“没有权限创建文件夹”。)
2、给已存在的镜像hello-world:latest打个标记

wang@wang:~$ docker tag hello-world:latest 127.0.0.1:5000/hello-world:1.11
wang@wang:~$ docker image ls
REPOSITORY                     TAG                 IMAGE ID            CREATED             SIZE
registry                       latest              2e2f252f3c88        2 months ago        33.3 MB
hello-world                    latest              f2a91732366c        12 months ago       1.85 kB
127.0.0.1:5000/hello-world     1.11                f2a91732366c        12 months ago       1.85 kB

3、把标记的镜像push到Registry

wang@wang:~$ docker push 127.0.0.1:5000/hello-world:1.11 
The push refers to a repository [127.0.0.1:5000/hello-world]
f999ae22f308: Pushed 
1.11: digest: sha256:0b1396cdcea05f91f38fc7f5aecd58ccf19fb5743bbb79cff5eb3c747b36d909 size: 524

4、删除刚刚打过标记的镜像(只是去掉标记)

wang@wang:~$ docker rmi 127.0.0.1:5000/hello-world:1.11 
Untagged: 127.0.0.1:5000/hello-world:1.11
Untagged: 127.0.0.1:5000/hello-world@sha256:0b1396cdcea05f91f38fc7f5aecd58ccf19fb5743bbb79cff5eb3c747b36d909
wang@wang:~$ docker image ls
REPOSITORY                     TAG                 IMAGE ID            CREATED             SIZE
registry                       latest              2e2f252f3c88        2 months ago        33.3 MB
hello-world                    latest              f2a91732366c        12 months ago       1.85 kB

5、用 curl 查看仓库中的镜像

wang@wang:~$ curl 127.0.0.1:5000/v2/_catalog
{"repositories":["hello-world"]}
或者
wang@wang:~$ curl http://localhost:5000/v2/hello-world/tags/list
{"name":"hello-world","tags":["1.11"]}

如上打印说明已经push成功了
6、前面已经删除已有镜像,尝试从私有仓库中下载这个镜像

wang@wang:~$ docker pull 127.0.0.1:5000/hello-world:1.11
打印:
1.11: Pulling from hello-world
Digest: sha256:0b1396cdcea05f91f38fc7f5aecd58ccf19fb5743bbb79cff5eb3c747b36d909
Status: Downloaded newer image for 127.0.0.1:5000/hello-world:1.11
wang@wang:~$ docker image ls
REPOSITORY                     TAG                 IMAGE ID            CREATED             SIZE
registry                       latest              2e2f252f3c88        2 months ago        33.3 MB
hello-world                    latest              f2a91732366c        12 months ago       1.85 kB
127.0.0.1:5000/hello-world     1.11                f2a91732366c        12 months ago       1.85 kB

pull成功了,简单测试就结束了。

wang@wang:~$ docker tag 127.0.0.1:5000/hello-world:1.11 hello-world:1.11
wang@wang:~$ docker rmi 127.0.0.1:5000/hello-world:1.11 
Untagged: 127.0.0.1:5000/hello-world:1.11
Untagged: 127.0.0.1:5000/hello-world@sha256:0b1396cdcea05f91f38fc7f5aecd58ccf19fb5743bbb79cff5eb3c747b36d909
wang@wang:~$ docker image ls
REPOSITORY                     TAG                 IMAGE ID            CREATED             SIZE
registry                       latest              2e2f252f3c88        2 months ago        33.3 MB
hello-world                    1.11                f2a91732366c        12 months ago       1.85 kB
hello-world                    latest              f2a91732366c        12 months ago       1.85 kB

其他ip在这个仓库pull镜像的设置:

修改/etc/docker下的daemon.json文件,没有的创建。内容如下:
{
  "registry-mirrors": ["https://registry.docker-cn.com"],
  "insecure-registries": ["本机ip:5000"]
}
需要符合json规范,否则Docker无法启动

重启docker服务:

sudo service docker restart
docker pull 本机ip:5000/hello-world:1.10

猜你喜欢

转载自blog.csdn.net/u010931295/article/details/84862407