1)安装组件nginx
[root@host2 ~]# yum install docker-registry -y
2)检查一下resitory的配置文件docker
[root@host2 ~]# vim /etc/docker-distribution/registry/config.yml
【里面的内容通常不用改动】json
version: 0.1 log: fields: service: registry storage: cache: layerinfo: inmemory filesystem: rootdirectory: /var/lib/registry http: addr: :5000
3)启动服务vim
[root@host2 ~]# systemctl start docker-distribution [root@host2 ~]# ss -tnl | grep 5000 LISTEN 0 128 [::]:5000 [::]:*
1)修改hosts文件,实现名称解析安全
[root@host1 ~]# echo "172.16.100.3 host2">>/etc/hosts [root@host1 ~]# ping host2
2)给一个现有的镜像打上标签
先随意找个镜像tcp
[root@host1 ~]# docker image ls | head -n2 REPOSITORY TAG IMAGE ID base v1.1 ca1046667ac3
给镜像打标签ide
[root@host1 ~]# docker tag base:v1.1 host2:5000/baseimg:v1-0
3)编辑docker配置文件
虽然此时已经制做好了镜像,可是还不能推送,由于docker默认用的https协议,而咱们的registry用的是http协议阿里云
[root@host1 ~]# vim /etc/docker/daemon.json
{ "registry-mirrors": [ "https://registry.docker-cn.com", "https://mzxx8xy8.mirror.aliyuncs.com" ], "hosts": ["tcp://0.0.0.0:3725", "unix://var/run/docker.sock"], "insecure-registries": ["host2:5000"] }
重启一下服务unix
[root@host1 ~]# systemctl daemon-reload [root@host1 ~]# systemctl restart docker
4)推送镜像rest
[root@host1 ~]# docker push host2:5000/baseimg:v1-0
推送的镜像会保存在服务的特定目录
[root@host2 ~]# ls /var/lib/registry/docker/registry/v2/repositories/ baseimg
1)修改docker配置文件,运行不安全的json
同:第二步
2)下载镜像
[root@host2 ~]# docker pull host2:5000/baseimg:v1-0
官方经过镜像发布了一个registry,只要启动容器就能够了
1)下载镜像
[root@host1 ~]# docker pull registry
2)第二步:建立目录
[root@host1 ~]# mkdir -p /opt/{auth,data} [root@host1 ~]# ls /opt/ auth data
3)第三步:建立认证文件
[root@host1 ~]# docker run --entrypoint \ > htpasswd registry -Bbn zxhk 123 > /opt/auth/htpasswd [root@host1 ~]# echo "0">/proc/sys/net/ipv4/ip_forward
4)第四步:建立容器
[root@host1 ~]# docker run -d -p 6000:5000 \ > --restart=always --name registry1 \ > -v /opt/auth:/auth -v /opt/data:/tmp/registry \ > -e "REGISTRY_AUTH=htpasswd" \ > -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \ > -e "REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd" \ > registry
1)修改docker配置文件,容许不安全的json
[root@host2 ~]# vim /etc/docker/daemon.json
{ "registry-mirrors": [ "https://registry.docker-cn.com", "https://mzxx8xy8.mirror.aliyuncs.com" ], "hosts": ["tcp://0.0.0.0:3725", "unix://var/run/docker.sock"], "insecure-registries": ["172.16.100.3:6000"] }
2)给镜像打标签
[root@host1 ~]# docker tag nginx:1.17-alpine 172.16.100.3:6000/nginx:v1-1
3)登陆registry
[root@host1 ~]# docker login http://172.16.100.3:6000
4)推送镜像
[root@host1 ~]# docker push 172.16.100.3:6000/nginx:v1-1