第七章:镜像仓库

  
 
1.私有镜像仓库搭建及使用
[root@linux-node1 ~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx v1 98d65c22dcf1 4 days ago 418MB
php v1 4af07ce50175 4 days ago 1.01GB
nginx v2 41238fb31cda 12 days ago 183MB
richarvey/nginx-php-fpm latest 1bb16fc4c08f 12 days ago 303MB
mysql latest 8d65ec712c69 2 weeks ago 445MB
nginx latest b175e7467d66 3 weeks ago 109MB
centos 7 e934aafc2206 4 weeks ago 199MB
busybox latest 8ac48589692a 4 weeks ago 1.15MB
nginx 1.11 5766334bdaa0 13 months ago 183MB
可以采用docker image save导出镜像包再使用。
docker pull默认去docker hub上下载拉取。
http://hub.docker.com/

  

(1)搭建私有镜像仓库
下载registry镜像并启动创建一个镜像仓库
[root@linux-node1 ~]# docker pull registry
[root@linux-node1 ~]# docker run -d -v /opt/registry:/var/lib/registry -p 5000:5000 --restart=always --name=registry registry
说明:指定数据卷-v /opt/registry,将私有镜像仓库上传的镜像持久化到本地宿主机上。
镜像仓库提供一个http接口的地址。
列出镜像:
[root@centos7 ~]# curl http://10.0.0.80:5000/v2/_catalog
{"repositories":[]}
  
(2)私有镜像仓库管理
国内的镜像地址:
[root@k8s-node01 ~]# docker pull nginx:1.12
[root@k8s-node01 ~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx 1.12 4037a5562b03 5 days ago 108MB

[root@linux-node1 ~]# cat /etc/docker/daemon.json
{
"registry-mirrors":[ "https://registry.docker-cn.com" ]
}
docker harbor是开源的企业级的私有镜像仓库。可以部署搭建。

====》
a.配置私有仓库可信任:
[root@k8s-node01 ~]# cat /etc/docker/daemon.json
{
"registry-mirrors": [ "https://registry.docker-cn.com"],
"insecure-registries":["10.0.0.80:5000"]
}
b.打标签:
[root@k8s-node01 ~]# docker tag nginx:1.12 10.0.0.80:5000/centos:7
[root@k8s-node01 ~]# docker tag nginx:1.12 10.0.0.212:5000/centos:7
[root@k8s-node01 ~]# docker tag nginx:1.12 10.0.0.80:5000/nginx:1.12
[root@k8s-node01 ~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
10.0.0.212:5000/centos 7 4037a5562b03 5 days ago 108MB
10.0.0.80:5000/centos 7 4037a5562b03 5 days ago 108MB
10.0.0.80:5000/nginx 1.12 4037a5562b03 5 days ago 108MB
nginx 1.12 4037a5562b03 5 days ago 108MB
c.上传:
[root@k8s-node01 ~]# docker push 10.0.0.80:5000/nginx:1.12
查看上传成功:
[root@k8s-node01 ~]# curl http://10.0.0.80:5000/v2/_catalog
{"repositories":["nginx"]}
[root@k8s-node01 ~]# curl http://10.0.0.80:5000/v2/nginx/tags/list
{"name":"nginx","tags":["1.12"]}

d.下载测试,没有的话会到镜像仓库拉取:
[root@k8s-node01 ~]# docker run -itd --name nginx -p 88:80 10.0.0.80:5000/nginx:1.12
583a12095044f633a36840ad0f04932fa4bad7021e664ca0b10d188f1bf3cb32
[root@k8s-node01 ~]# docker container ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
583a12095044 10.0.0.80:5000/nginx:1.12 "nginx -g 'daemon of…" 4 seconds ago Up 1 second 0.0.0.0:88->80/tcp nginx

[root@k8s-node01 ~]# docker rm -f $(docker ps -q -a)
[root@k8s-node01 ~]# docker run -itd --name nginx -p 88:80 10.0.0.80:5000/nginx:1.12
c6cb960eed972a08a792e9a8688df66bd16b366fd800dee23a0911fc8f4c96d3
[root@k8s-node01 ~]#
[root@k8s-node01 ~]# docker images ps
REPOSITORY TAG IMAGE ID CREATED SIZE
[root@k8s-node01 ~]# docker container ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c6cb960eed97 10.0.0.80:5000/nginx:1.12 "nginx -g 'daemon of…" 18 seconds ago Up 17 seconds 0.0.0.0:88->80/tcp nginx

输入http://10.0.0.212:88/
Welcome to nginx!
e.列出镜像标签:
[root@k8s-node01 ~]# curl http://10.0.0.80:5000/v2/centos/tags/list
{"errors":[{"code":"NAME_UNKNOWN","message":"repository name not known to registry","detail":{"name":"centos"}}]}


2.公共镜像仓库
https://hub.docker.com/_/nginx/
  

posted @ 2018-05-06 17:46  bkycrmn  阅读(151)  评论(0)    收藏  举报