Registry 仓库搭建如下
环境准备
主机 | IP地址 |
---|---|
Registry 私有仓库 | 192.168.1.10 |
测试端 | 192.168.1.20 |
搭建过程如下
Registry服务端的配置
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# yum install -y docker //安装docker
[root@localhost ~]# vim /etc/sysconfig/docker //修改配置文件
OPTIONS='--selinux-enabled --log-driver=journald --signature-verification=false --insecure-registry 192.168.1.10:5000' //添加一个参数以 --insecure开头的
ADD_REGISTRY='--add-registry 192.168.1.10:5000' //增加一条这个
[root@localhost ~]# systemctl start docker
[root@localhost ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@localhost ~]# docker search registry //查找镜像
[root@localhost ~]# docker pull docker.io/registry //查找好了以后进行下载操作
[root@localhost /]# docker images //查询本地镜像库
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/registry latest c9bd19d022f6 4 years ago 33.3 MB
[root@localhost /]# docker run -itd --name=registry -p 5000:5000 --restart=always docker.io/registry:latest //然后启动registry仓库即可
35a2a78923182213d46d85ea9bc1d550f6e39d22dc5cdf049d2fd439375cbc21
[root@localhost /]# docker ps //查看容器的状况
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
35a2a7892318 docker.io/registry:latest "/entrypoint.sh /e..." 24 seconds ago Up 23 seconds 0.0.0.0:5000->5000/tcp registry
[root@localhost /]# ss -tan | grep 5000
LISTEN 0 128 [::]:5000 [::]:*
[root@localhost ~]# docker tag c9bd19d022f6 192.168.1.10:5000/registry:latest //打标
[root@localhost ~]# docker push 192.168.1.10:5000/registry:latest //然后上传到私有仓库里面去
The push refers to a repository [192.168.1.10:5000/registry]
9b728062fb6d: Pushed
481c807467a1: Pushed
a049b9c716b3: Pushed
d57f828d06ea: Pushed
011b303988d2: Pushed
[root@localhost ~]# curl 192.168.1.10:5000/v2/_catalog //查询仓库存在的镜像
{"repositories":["registry"]}
我们可以上传一个镜像到仓库里面,然后客户端使用docker pull下载测试
[root@localhost /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.1.10:5000/nginx latest 3f8a4339aadd 2 years ago 108 MB
上传好Nginx镜像进行打包操作
[root@localhost /]# docker push 192.168.1.10:5000/nginx:latest //上传到registry私有仓库
[root@localhost /]# curl 192.168.1.10:5000/v2/_catalog
{"repositories":["nginx","registry"]}
客户端测试
[root@localhost ~]# yum install -y docker //安装docker
[root@localhost ~]# vim /etc/docker/daemon.json //编辑该文件,写入如下内容
{
"insecure-registries":["192.168.1.10:5000"] //添加私有仓库的地址
}
~
[root@localhost ~]# systemctl start docker
[root@localhost ~]# systemctl enable docker
[root@localhost ~]# curl 192.168.1.10:5000/v2/_catalog
{"repositories":["nginx","registry"]}
客户端查看registry私有仓库存在的镜像
[root@localhost ~]# docker pull 192.168.1.10:5000/nginx:latest //然后下载镜像
[root@localhost ~]# docker images //然后查看下载的镜像
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.1.10:5000/nginx latest 3f8a4339aadd 2 years ago 108 MB