Docker 搭建本地Registry


 

Docker已經將Registry開源,Registry本身也是一個容器。

1. 修改配置/etc/docker/daemon.json,去掉docker默認的https的訪問
   里面的內容是一個json對象,加上一項insecure-registries:

{
"insecure-registries":["172.16.65.150:5000"],
"registry-mirrors": ["http://2555a638.m.daocloud.io"]
}

 

2. 啟動Registry容器

復制代碼
root@Docker001:~# docker run --name registry -d -p 5000:5000 -v /myregistry/:/var/lib/registry registry:2
Unable to find image 'registry:2' locally
2: Pulling from library/registry
81033e7c1d6a: Pull complete 
b235084c2315: Pull complete 
c692f3a6894b: Pull complete 
ba2177f3a70e: Pull complete 
a8d793620947: Pull complete 
Digest: sha256:6cd209f81e188e8eaa13fad9b670fb1a4e9c7776a73b3881b69834fe5ddfb193
Status: Downloaded newer image for registry:2
385252aac02931701c4cae4233d1b12447b5b8b98ba6b337121d2f4a03e78709
root@Docker001:~# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
385252aac029        registry:2          "/entrypoint.sh /e..."   9 seconds ago       Up 8 seconds        0.0.0.0:5000->5000/tcp   registry
復制代碼

 

3. 測試Registry是否工作正常

root@Docker001:~# curl http://172.16.65.150:5000/v2/_catalog
{"repositories":[]}
root@Docker001:~# 

 只要返回值為 {"repositories":[]} 表示工作正常。

 

4. 給本地Image打上本地Registry標簽

復制代碼
root@Docker001:~# docker tag centos-with-vim 172.16.65.150:5000/centos-with-vim
root@Docker001:~# docker images
REPOSITORY                              TAG                 IMAGE ID            CREATED             SIZE
centos-with-vim                         latest              c00312958340        5 days ago          359 MB
172.16.65.150:5000/centos-with-vim      latest              c00312958340        5 days ago          359 MB
httpd                                   latest              01154c38b473        2 weeks ago         177 MB
debian                                  latest              1b3ec9d977fb        2 weeks ago         100 MB
registry                                2                   d1fd7d86a825        7 weeks ago         33.3 MB
centos                                  latest              ff426288ea90        7 weeks ago         207 MB
hello-world                             latest              f2a91732366c        3 months ago        1.85 kB
vincenshen/hello-world                  v1                  f2a91732366c        3 months ago        1.85 kB
172.16.65.150:5000/hello-world          latest              f2a91732366c        3 months ago        1.85 kB
docker001:5000/vincenshen/hello-world   v1                  f2a91732366c        3 months ago        1.85 kB
django                                  latest              eb40dcf64078        14 months ago       436 MB
root@Docker001:~# 
復制代碼

在鏡像的前面加上了運行 registry 的主機名稱和端口。
鏡像名稱由 repository 和 tag 兩部分組成。而 repository 的完整格式為:[registry-host]:[port]/[username]/xxx
只有 Docker Hub 上的鏡像可以省略 [registry-host]:[port] 。

 

5. 上傳Image到Registry

root@Docker001:~# docker push 172.16.65.150:5000/centos-with-vim
The push refers to a repository [172.16.65.150:5000/centos-with-vim]
b00cb99cc959: Pushed 
e15afa4858b6: Pushed 
latest: digest: sha256:cc103061080dde196f30aa3cb2a129a3be90dd882c0542f27d44509705802544 size: 741

 

6. 查看Registry中的Image信息

root@Docker001:~# curl http://172.16.65.150:5000/v2/_catalog
{"repositories":["centos-with-vim"]}

root@Docker001:~# curl http://172.16.65.150:5000/v2/centos-with-vim/tags/list
{"name":"centos-with-vim","tags":["latest"]}

 

7. 刪除Registry中的Image

 刪除鏡像

docker exec <Registry-容器名> rm -rf /var/lib/registry/docker/registry/v2/repositories/<鏡像名>

 清理配置信息

 docker exec <Registry-容器名> bin/registry garbage-collect /etc/docker/registry/config.yml

 

更多詳細配置https://docs.docker.com/registry/configuration


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM