learning docker steps(7) ----- docker registry 搭建

参考:

https://docs.docker.com/engine/reference/builder/

https://hub.docker.com/_/registry/

https://www.cnblogs.com/vikings-blog/p/3972370.html

https://docs.docker.com/registry/deploying/#customize-the-published-port

针对registry的理解,我们可以类比github.com,网站。

在本地搭建git服务器,自已的私有仓库。当然公司内部也有需要,在公司内部搭建registry服务

按如下操作可实现本地搭建docker registry

1. 运行私有仓库的镜像管理服务registry
root@vmuser-virtual-machine:/home/vmuser# docker run -d -p 5000:5000 –restart always –name registry registry:2.6.2
Unable to find image ‘registry:2.6.2’ locally
2.6.2: Pulling from library/registry
d6a5679aa3cf: Pull complete
ad0eac849f8f: Pull complete
2261ba058a15: Pull complete
f296fda86f10: Pull complete
bcd4a541795b: Pull complete
Digest: sha256:5a156ff125e5a12ac7fdec2b90b7e2ae5120fa249cf62248337b6d04abc574c8
Status: Downloaded newer image for registry:2.6.2
68448c14a29ce0bcd07fc2edcf387dc216ed87a36d9eac8db8acfaa0b3c2406b
root@vmuser-virtual-machine:/home/vmuser# docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
68448c14a29c registry:2.6.2 “/entrypoint.sh /etc…” 37 seconds ago Up 36 seconds 0.0.0.0:5000->5000/tcp registry

2. 查看当前的厂库镜像
安装registry-cli及相关的依赖:
root@vmuser-virtual-machine:/home/vmuser/workdir/registry-docker# git clone https://github.com/andrey-pohilko/registry-cli
正克隆到 ‘registry-cli’…
remote: Counting objects: 276, done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 276 (delta 4), reused 6 (delta 2), pack-reused 264
接收对象中: 100% (276/276), 103.26 KiB | 190.00 KiB/s, 完成.
处理 delta 中: 100% (138/138), 完成.
root@vmuser-virtual-machine:/home/vmuser/workdir/registry-docker/registry-cli# pip install requests
Collecting requests
Downloading https://files.pythonhosted.org/packages/65/47/7e02164a2a3db50ed6d8a6ab1d6d60b69c4c3fdf57a284257925dfc12bda/requests-2.19.1-py2.py3-none-any.whl (91kB)
100% |████████████████████████████████| 92kB 162kB/s
Requirement already satisfied: idna<2.8,>=2.5 in /usr/lib/python2.7/dist-packages (from requests)
Collecting certifi>=2017.4.17 (from requests)
Downloading https://files.pythonhosted.org/packages/df/f7/04fee6ac349e915b82171f8e23cee63644d83663b34c539f7a09aed18f9e/certifi-2018.8.24-py2.py3-none-any.whl (147kB)
100% |████████████████████████████████| 153kB 501kB/s
Collecting chardet<3.1.0,>=3.0.2 (from requests)
Downloading https://files.pythonhosted.org/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl (133kB)
100% |████████████████████████████████| 143kB 1.7MB/s
Collecting urllib3<1.24,>=1.21.1 (from requests)
Downloading https://files.pythonhosted.org/packages/bd/c9/6fdd990019071a4a32a5e7cb78a1d92c53851ef4f56f62a3486e6a7d8ffb/urllib3-1.23-py2.py3-none-any.whl (133kB)
100% |████████████████████████████████| 143kB 2.1MB/s
Installing collected packages: certifi, chardet, urllib3, requests
Successfully installed certifi-2018.8.24 chardet-3.0.4 requests-2.19.1 urllib3-1.23

开启registry服务:

root@vmuser-virtual-machine:/home/vmuser/workdir/registry-docker/registry-cli# python registry.py -r http://localhost:5000
Traceback (most recent call last):
File “registry.py”, line 13, in <module>
import www_authenticate  --- 缺少相关的python库,我们手动安装下
ImportError: No module named www_authenticate
root@vmuser-virtual-machine:/home/vmuser/workdir/registry-docker/registry-cli# pip install www_authenticate
Collecting www_authenticate
Downloading https://files.pythonhosted.org/packages/a7/2d/5567291a8274ef5d9b6495a1ec341394ab68933e2396936755b157f87b43/www-authenticate-0.9.2.tar.gz
Building wheels for collected packages: www-authenticate
Running setup.py bdist_wheel for www-authenticate … done
Stored in directory: /root/.cache/pip/wheels/dd/64/7f/62727305e6bba21e34bbdb8017d4770b6109d8028463454a35
Successfully built www-authenticate
Installing collected packages: www-authenticate
Successfully installed www-authenticate-0.9.2
因为当前的厂库为空,所以如下显示无显示:
root@vmuser-virtual-machine:/home/vmuser/workdir/registry-docker/registry-cli# python registry.py -r http://localhost:5000

3 将docker ubuntu:16.04 下载至本地,并查看,并将其上传至本地registry,然后下载至本地
root@vmuser-virtual-machine:/home/vmuser/workdir/registry-docker/registry-cli# docker pull ubuntu:16.04
16.04: Pulling from library/ubuntu
3b37166ec614: Pull complete
504facff238f: Pull complete
ebbcacd28e10: Pull complete
c7fb3351ecad: Pull complete
2e3debadcbf7: Pull complete
Digest: sha256:45ddfa61744947b0b8f7f20b8de70cbcdd441a6a0532f791fd4c09f5e491a8eb
Status: Downloaded newer image for ubuntu:16.04
root@vmuser-virtual-machine:/home/vmuser/workdir/registry-docker/registry-cli# docker tag ubuntu:16.04 localhost:5000/myubuntu:16.04

root@vmuser-virtual-machine:/home/vmuser/workdir/registry-docker/registry-cli# docker push localhost:5000/myubuntu:16.04
The push refers to repository [localhost:5000/myubuntu]
75b79e19929c: Pushed
4775b2f378bb: Pushed
883eafdbe580: Pushed
19d043c86cbc: Pushed
8823818c4748: Pushed
16.04: digest: sha256:9b47044b1e79b965a8e1653e7f9c04b5f63e00b9161bedd5baef69bb8b4c4834 size: 1357

通过如下命令可查看到本地的docker registry存在的docker镜像:
root@vmuser-virtual-machine:/home/vmuser/workdir/registry-docker/registry-cli# python registry.py -r http://localhost:5000
———————————
Image: myubuntu
tag: 16.04

通过如下指令拉下来,测试存在本地的docker registry是否可以运行?
root@vmuser-virtual-machine:/home/vmuser/workdir/registry-docker/registry-cli# docker pull localhost:5000/myubuntu:16.04
16.04: Pulling from myubuntu
Digest: sha256:9b47044b1e79b965a8e1653e7f9c04b5f63e00b9161bedd5baef69bb8b4c4834
Status: Image is up to date for localhost:5000/myubuntu:16.04
root@vmuser-virtual-machine:/home/vmuser/workdir/registry-docker/registry-cli# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
registry 2.6.2 2e2f252f3c88 4 days ago 33.3MB
localhost:5000/myubuntu 16.04 b9e15a5d1e1a 10 days ago 115MB
ubuntu latest cd6d8154f1e1 10 days ago 84.1MB

原文地址:https://www.cnblogs.com/lianghong881018/p/10174964.html