您的位置:首页 > 运维架构 > Docker

docker 四 搭建本地仓库 Registry

2020-02-06 19:49 211 查看

简述: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

  • 点赞
  • 收藏
  • 分享
  • 文章举报
renren-100 发布了7 篇原创文章 · 获赞 1 · 访问量 133 私信 关注
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: