docker 四 搭建本地仓库 Registry
简述:Docker 已经将Registry开源,其本身也是一个容器。
1,拉取registry 镜像
------ docker pull registry
[root@localhost docker]# docker pull 10.0.0.4:5000/nginx Using default tag: latest latest: Pulling from nginx 000eee12ec04: Pull complete eb22865337de: Pull complete bee5d581ef8b: Pull complete Digest: sha256:189cce606b29fb2a33ebc2fcecfa8e33b0b99740da4737133cdbcee92f3aba0a Status: Downloaded newer image for 10.0.0.4:5000/nginx:latest 10.0.0.4:5000/nginx:latest
2,修改配置文件/etc/docker/daemon.json 将宿主机的IP 添加进去
{
“insecure-registries”:[“10.0.0.4:5000”], ------------------->>>>>>> # 千万要注意逗号
}
3,启动 registry 容器
docker run --name registry -d -p 5000:5000 -v /myregistry/:/var/lib/registry
4,测试Registry 是否工作正常
curl http://10.0.0.4:5000/v2/_catalog
只要返回值为 {“repositories”:[]} 表示工作正常。
[root@localhost docker]# curl http://10.0.0.4:5000/v2/_catalog {"repositories":["nginx"]}
5,给本地Image打上本地Registry 标签。
docker tag nginx 10.0.0.4:5000/nginx
[root@localhost docker]# docker image rm 10.0.0.4:5000/nginx Untagged: 10.0.0.4:5000/nginx:latest Untagged: 10.0.0.4:5000/nginx@sha256:189cce606b29fb2a33ebc2fcecfa8e33b0b99740da4737133cdbcee92f3aba0a [root@localhost docker]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest 231d40e811cd 3 weeks ago 126MB centos latest 0f3e07c0138f 2 months ago 220MB 10.0.0.4:5000/registry latest f32a97de94e1 9 months ago 25.8MB registry latest f32a97de94e1 9 months ago 25.8MB hello-world latest fce289e99eb9 11 months ago 1.84kB [root@localhost docker]# docker tag nginx 10.0.0.4:5000/nginx [root@localhost docker]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE 10.0.0.4:5000/nginx latest 231d40e811cd 3 weeks ago 126MB nginx latest 231d40e811cd 3 weeks ago 126MB centos latest 0f3e07c0138f 2 months ago 220MB 10.0.0.4:5000/registry latest f32a97de94e1 9 months ago 25.8MB registry latest f32a97de94e1 9 months ago 25.8MB hello-world latest fce289e99eb9 11 months ago 1.84kB
在镜像的前面加上了运行 registry 的主机名称和端口。
镜像名称由 repository 和 tag 两部分组成。而 repository 的完整格式为:[registry-host]:[port]/[username]/xxx
只有 Docker Hub 上的镜像可以省略 [registry-host]:[port] 。
6,上传Image到Registry
[root@localhost ~]# docker push 10.0.0.4:5000/nginx
[root@localhost ~]# docker push 10.0.0.4:5000/nginx The push refers to repository [10.0.0.4:5000/nginx] 4fc1aa8003a3: Pushed 5fb987d2e54d: Pushed 831c5620387f: Pushed latest: digest: sha256:189cce606b29fb2a33ebc2fcecfa8e33b0b99740da4737133cdbcee92f3aba0a size: 948
7,删除Registry 中的Image
删除镜像
docker exec <Registry-容器名> rm -rf /var/lib/registry/docker/registry/v2/repositories/<镜像名>
------------------- 或是registry ID
具体代码:
[root@localhost ~]# vi /etc/docker/daemon.json [root@localhost ~]# cat /etc/docker/daemon.json { "insecure-registries":["10.0.0.4:5000"], "registry-mirrors":["https://tpmrvmq9.mirror.aliyuncs.com"] } [root@localhost ~]# systemctl restart docker [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest 231d40e811cd 3 weeks ago 126MB centos latest 0f3e07c0138f 2 months ago 220MB registry latest f32a97de94e1 9 months ago 25.8MB hello-world latest fce289e99eb9 11 months ago 1.84kB [root@localhost ~]# ls anaconda-ks.cfg registry-191214.tar [root@localhost ~]# docker run --name registry -d -p 5000:5000 -v /myregistry/:/var/lib/registry registry 4260a1f66517b321ca02c869883b38d46f28e831bd3f15d442404bc59fdf3fe6 [root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 4260a1f66517 registry "/entrypoint.sh /etc…" 13 seconds ago Up 9 seconds 0.0.0.0:5000->5000/tcp registry [root@localhost ~]# curl http://10.0.0.4:5000/v2/_catalog {"repositories":[]} [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest 231d40e811cd 3 weeks ago 126MB centos latest 0f3e07c0138f 2 months ago 220MB registry latest f32a97de94e1 9 months ago 25.8MB hello-world latest fce289e99eb9 11 months ago 1.84kB [root@localhost ~]# docker tag nginx 10.0.0.4:5000/nginx [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE 10.0.0.4:5000/nginx latest 231d40e811cd 3 weeks ago 126MB nginx latest 231d40e811cd 3 weeks ago 126MB centos latest 0f3e07c0138f 2 months ago 220MB registry latest f32a97de94e1 9 months ago 25.8MB hello-world latest fce289e99eb9 11 months ago 1.84kB [root@localhost ~]# docker push 10.0.0.4:5000/nginx The push refers to repository [10.0.0.4:5000/nginx] 4fc1aa8003a3: Pushed 5fb987d2e54d: Pushed 831c5620387f: Pushed latest: digest: sha256:189cce606b29fb2a33ebc2fcecfa8e33b0b99740da4737133cdbcee92f3aba0a size: 948[root@localhost ~]# curl http://10.0.0.4:5000/v2/_catalog {"repositories":["nginx"]} [root@localhost ~]# curl http://10.0.0.4:5000/v2/nginx/tags/list {"name":"nginx","tags":["latest"]} [root@localhost ~]# cat /etc/docker/daemon.json { "insecure-registries":["10.0.0.4:5000"], "registry-mirrors":["https://tpmrvmq9.mirror.aliyuncs.com"] } [root@localhost v2]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest 231d40e811cd 3 weeks ago 126MB centos latest 0f3e07c0138f 2 months ago 220MB 10.0.0.4:5000/registry latest f32a97de94e1 9 months ago 25.8MB registry latest f32a97de94e1 9 months ago 25.8MB hello-world latest fce289e99eb9 11 months ago 1.84kB [root@localhost v2]# docker pull 10.0.0.4:5000/nginx Using default tag: latest latest: Pulling from nginx Digest: sha256:189cce606b29fb2a33ebc2fcecfa8e33b0b99740da4737133cdbcee92f3aba0a Status: Downloaded newer image for 10.0.0.4:5000/nginx:latest 10.0.0.4:5000/nginx:latest [root@localhost v2]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE 10.0.0.4:5000/nginx latest 231d40e811cd 3 weeks ago 126MB nginx latest 231d40e811cd 3 weeks ago 126MB centos latest 0f3e07c0138f 2 months ago 220MB registry latest f32a97de94e1 9 months ago 25.8MB 10.0.0.4:5000/registry latest f32a97de94e1 9 months ago 25.8MB hello-world latest fce289e99eb9 11 months ago 1.84kB [root@localhost v2]# docker tag registry 10.0.0.4:5000/registry [root@localhost v2]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE 10.0.0.4:5000/nginx latest 231d40e811cd 3 weeks ago 126MB nginx latest 231d40e811cd 3 weeks ago 126MB centos latest 0f3e07c0138f 2 months ago 220MB registry latest f32a97de94e1 9 months ago 25.8MB 10.0.0.4:5000/registry latest f32a97de94e1 9 months ago 25.8MB hello-world latest fce289e99eb9 11 months ago 1.84kB [root@localhost v2]# docker push 10.0.0.4:5000/registry The push refers to repository [10.0.0.4:5000/registry] 73d61bf022fd: Pushed 5bbc5831d696: Pushed d5974ddb5a45: Pushed f641ef7a37ad: Pushed d9ff549177a9: Pushed latest: digest: sha256:b1165286043f2745f45ea637873d61939bff6d9a59f76539d6228abf79f87774 size: 1363 [root@localhost v2]# curl http://10.0.0.4:5000/v2/_catalog {"repositories":["nginx","registry"]} [root@localhost v2]# curl http://10.0.0.4:5000/v2/_catalog {"repositories":["nginx","registry"]} [root@localhost v2]# docker exec 4260a1f66517 rm -rf /var/lib/registry/docker/registry/v2/repositories/registry [root@localhost v2]# curl http://10.0.0.4:5000/v2/_catalog {"repositories":["nginx"]} [root@localhost v2]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE 10.0.0.4:5000/nginx latest 231d40e811cd 3 weeks ago 126MB nginx latest 231d40e811cd 3 weeks ago 126MB centos latest 0f3e07c0138f 2 months ago 220MB 10.0.0.4:5000/registry latest f32a97de94e1 9 months ago 25.8MB registry latest f32a97de94e1 9 months ago 25.8MB hello-world latest fce289e99eb9 11 months ago 1.84kB
https://www.cnblogs.com/vincenshen/p/8490545.html **来源**
2019-12-15
- 点赞
- 收藏
- 分享
- 文章举报
- docker学习笔记(二)——本地私有仓库Registry的搭建与验证
- docker私有仓库registry的本地搭建
- Docker搭建本地仓库registry
- 搭建 Docker-Registry 私有仓库
- 利用registry搭建局域网docker私有仓库
- docker registry2 仓库搭建与使用
- docker本地仓库的搭建
- Docker搭建自己的本地镜像仓库的步骤
- docker基础:私有仓库repository搭建(1):registry
- Docker registry仓库搭建配置简介
- Docker私有仓库Registry搭建(localhost 可行但跨主机有问题)
- docker本地仓库搭建
- docker本地私有仓库搭建
- 搭建本地 Registry - 每天5分钟玩转 Docker 容器技术(20)
- 微服务架构 - 搭建docker本地镜像仓库并提供权限校验及UI界面
- Docker Registry搭建私有镜像仓库的实现方法
- Docker之Registry私有仓库+Harbor私有仓库的搭建
- Docker私有仓库Registry的搭建验证
- 在 ubuntu 搭建 docker registry 私有仓库
- docker-registry 搭建私有仓库服务器