docker可以使用阿里云的私服,也可以自己公司进行搭建,阿里云的自己看阿里云,下面主要将公司内私服搭建
1、拉取私服镜像
docker pull registry
2、启动registry
docker run -d -p 5000:5000 -v /data/myregistry/:/tmp/registry --privileged=true registry
默认情况下,仓库被创建在容器的/var/lib/registry目录下,可自行用容器卷映射,方便宿主机联调。
3、提交镜像
docker commit -m="lmytest" -a="lmy" 2c8c6b67c4e5 centos:1.0
4、标记本地镜像
docker tag centos:1.0 192.168.236.130:5000/centos:1.0
查看本地镜像,这时可以看到标记后的镜像已经生成
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.236.130:5000/centos 1.0 3cf73170be02 5 minutes ago 559MB
centos 1.0 3cf73170be02 5 minutes ago 559MB
5、推送镜像到私服
docker push 192.168.236.130:5000/centos:1.0
如果出现如下错误:说明docker registry默认不运行http推送镜像,需要使用https
The push refers to repository [192.168.236.130:5000/centos]
Get "https://192.168.236.130:5000/v2/": http: server gave HTTP response to HTTPS client
解决方法
修改/etc/docker/daemon.json,增加 “insecure-registries”:[“192.168.236.130:5000”] 注意json格式前面有个逗号
vim /etc/docker/daemon.json
{
"registry-mirrors": ["https://xxxx.mirror.aliyuncs.com"],
"insecure-registries":["192.168.236.130:5000"]
}
重启docker
systemctl restart docker
注意重启完后,再次启动私服,然后再执行推送命令
6、查看私服中的镜像
[root@localhost ~]# curl -XGET http://192.168.236.130:5000/v2/_catalog
{"repositories":["centos"]}
这时可以看到已经上传上去;
7、下拉镜像
docker pull 192.168.236.130:5000/centos:1.0