1.普通的registry
#上传镜像包
#导入镜像包
[root@docker01 ~]# docker load -i registry.tar.gz
ef763da74d91: Loading layer 5.058MB/5.058MB
7683d4fcdf4e: Loading layer 7.894MB/7.894MB
656c7684d0bd: Loading layer 22.79MB/22.79MB
a2717186d7dd: Loading layer 3.584kB/3.584kB
3c133a51bc00: Loading layer 2.048kB/2.048kB
Loaded image: registry:latest
#启动容器并指定端口映射和volum卷挂载以及设置容器开机自启
[root@docker01 ~]# docker run -d -p 5000:5000 --restart=always --name registry -v /opt/myregistry:/var/lib/registry registry
a424b4aae7d8dde85e3efb5454c8558afc45e28eb34bce971a02fb541c5bb94b
[root@docker01 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a424b4aae7d8 registry "/entrypoint.sh /etc…" 15 seconds ago Up 14 seconds 0.0.0.0:5000->5000/tcp registry
上传镜像到私有仓库
1.给镜像打标签(指定域名或ip,也就是指定上传到那个仓,无指定默认上传到GitHub)
[root@docker02 ~]# docker tag centos:7 10.0.0.55:5000/centos7
2.上传镜像(镜像同名会存在同名覆盖,注意标签命名)
##遇报错
[root@docker02 ~]# docker push 10.0.0.55:5000/centos7
The push refers to repository [10.0.0.55:5000/centos7]
Get https://10.0.0.55:5000/v2/: http: server gave HTTP response to HTTPS client
#添加仓库白名单
[root@docker02 ~]# vim /etc/docker/daemon.json
{
"registry-mirrors": ["https://ig2l319y.mirror.aliyuncs.com"],
"insecure-registries": ["http://10.0.0.55:5000"]
}
#重启docker服务
[root@docker02 ~]# systemctl restart docker.service
#重新上传
[root@docker02 ~]# docker push 10.0.0.55:5000/centos7
The push refers to repository [10.0.0.55:5000/centos7]
77b174a6a187: Pushed
latest: digest: sha256:285bc3161133ec01d8ca8680cd746eecbfdbc1faa6313bd863151c4b26d7e5a5 size: 529
#宿主机查看上传是存在
[root@docker01 /opt/myregistry/docker/registry/v2/repositories]# ls
centos7
#下载镜像
[root@docker02 ~]# docker pull 10.0.0.55:5000/centos7
Using default tag: latest
latest: Pulling from centos7
Digest: sha256:285bc3161133ec01d8ca8680cd746eecbfdbc1faa6313bd863151c4b26d7e5a5
Status: Image is up to date for 10.0.0.55:5000/centos7:latest
10.0.0.55:5000/centos7:latest
2.带basic认证的私有仓库
[root@docker01 ~]# yum install httpd-tools -y
[root@docker01 ~]# mkdir /opt/registry-var/auth/ -p
[root@docker01 ~]# htpasswd -Bbn weiaixiong 123456 >> /opt/registry-var/auth/htpasswd
[root@docker01 ~]# docker run -d -p 5000:5000 -v /opt/registry-var/auth/:/auth/ -v /opt/myregistry:/var/lib/registry -e "REGISTRY_AUTH=htpasswd" -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" -e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd registry
提示:上传下载镜像都需要登陆哦
docker login 10.0.0.55:5000
weiaixiaong
123456
docker logout 10.0.0.55:5000登出
验证身份登录
查看镜像列表
使用浏览器访问:
http://10.0.0.55:5000/v2/_catalog
查看镜像的版本
下面我已centos7为例 registry3.png
网友评论