使用公共仓库
登陆官方网站:https://hub.docker.com/ 注册账号和密码
在Docker hub中创建一个资源, create respositories, 创建后会提示如何push镜像到公共仓库
当提示: docker push dai163309889254/zabbix:tagname 时, 使用该命令push镜像
在Docker主机上面, 把需要推送的镜像命名为 dai163309889254/zabbix:latest
docker tag zabbix:latest dai163309889254/zabbix:latest
登陆docker hub开始推送
docker login
# 输入注册的docker hub的账号密码
# 开始推送镜像
docker push dai163309889254/zabbix:latest
最后登陆到Docker Hub上面就可以看到镜像的信息(镜像大小,最后一次推送时间等信息)
使用私有仓库
docker 已经打包好了一个镜像仓库, 直接下载并运行即可
创建好使用的配置文件
#cat config.yml
version:0.1log:
fields:
service: registry
storage:
delete:
enabled:truecache:
blobdescriptor: inmemory
filesystem:
rootdirectory:/var/lib/registry
http:
addr: :7000headers:
X-Content-Type-Options: [nosniff]
health:
storagedriver:
enabled:trueinterval: 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