1.普通的registry
#上傳鏡像包
#導(dǎo)入鏡像包
[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
#啟動(dòng)容器并指定端口映射和volum卷掛載以及設(shè)置容器開(kāi)機(jī)自啟
[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
上傳鏡像到私有倉(cāng)庫(kù)
1.給鏡像打標(biāo)簽(指定域名或ip,也就是指定上傳到那個(gè)倉(cāng),無(wú)指定默認(rèn)上傳到GitHub)
[root@docker02 ~]# docker tag centos:7 10.0.0.55:5000/centos7
2.上傳鏡像(鏡像同名會(huì)存在同名覆蓋笔喉,注意標(biāo)簽命名)
##遇報(bào)錯(cuò)
[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
#添加倉(cāng)庫(kù)白名單
[root@docker02 ~]# vim /etc/docker/daemon.json
{
"registry-mirrors": ["https://ig2l319y.mirror.aliyuncs.com"],
"insecure-registries": ["http://10.0.0.55:5000"]
}
#重啟docker服務(wù)
[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
#宿主機(jī)查看上傳是存在
[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認(rèn)證的私有倉(cāng)庫(kù)
[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登出
驗(yàn)證身份登錄
查看鏡像列表
使用瀏覽器訪問(wèn):
http://10.0.0.55:5000/v2/_catalog
查看鏡像的版本
下面我已centos7為例
http://10.0.0.55:5000/v2/centos7/tags/list