Docker系列六: 使用Docker官方公共仓库和私有仓库

使用公共仓库docker

登录官方网站:https://hub.docker.com/   注册帐号和密码浏览器

在Docker hub中建立一个资源,  create  respositories,   建立后会提示如何push镜像到公共仓库curl

当提示: docker push dai163309889254/zabbix:tagname  时, 使用该命令push镜像tcp

 

在Docker主机上面, 把须要推送的镜像命名为 dai163309889254/zabbix:latest网站

docker tag zabbix:latest dai163309889254/zabbix:latest

 

登录docker hub开始推送url

docker login
# 输入注册的docker hub的帐号密码

# 开始推送镜像
docker push dai163309889254/zabbix:latest

 

最后登录到Docker Hub上面就能够看到镜像的信息(镜像大小,最后一次推送时间等信息)spa

 

使用私有仓库rest

docker 已经打包好了一个镜像仓库, 直接下载并运行便可code

 

建立好使用的配置文件server

#cat config.yml
 
version: 0.1
log:
  fields:
    service: registry
storage:
  delete:
    enabled: true
  cache:
    blobdescriptor: inmemory
  filesystem:
    rootdirectory: /var/lib/registry
http:
  addr: :7000
  headers:
    X-Content-Type-Options: [nosniff]
health:
  storagedriver:
    enabled: true
    interval: 10s
    threshold: 3

 

运行容器

docker run -d -p 7000:7000 -v /opt/data/registry:/var/lib/registry  -v /data/config.yml:/etc/docker/registry/config.yml  registry 

 

当容器运行时,会监听7000端口

使用浏览器或者curl访问tcp的7000端口返回   {}  表示运行成功

 

修改docker配置解决推送时提示 http: server gave HTTP response to HTTPS client, 由于Docker从1.3.X以后,与docker registry交互默认使用的是https,然而此处搭建的私有仓库只提供http服务,因此当与私有仓库交互时就会报上面的错误。为了解决这个问题须要在启动docker server时增长启动参数为默认使用http访问。修改docker启动配置文件:

{
  "registry-mirrors":["http://hub-mirror.c.163.com"],   #镜像加速
  "insecure-registries":["172.16.27.139:7000"]         # 添加非ssl仓库
}

 

重启docker服务

service docker restart

 

修改镜像名称为本地镜像名称

docker tag zabbix:latest 172.16.27.139:7000/zabbix:latest

 

推送镜像到本地仓库

docker push 172.16.27.139:7000/zabbix:latest

 

查看是否存在镜像

http://172.16.27.139:7000/v2/_catalog
相关文章
相关标签/搜索