一、基础环境准备:
1:安装好docker,配置可以访问外网的网卡和yum源。
二、从docker hub官方网站下载registry镜像
docker pull registry
启动registry容器:
docker run -d -v /opt/registry:/var/lib/registry -p 5000:5000 --restart=always --name registry registry:latest
查看registry容器:
[root@kolla ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9c79dbd0992d registry:latest "/entrypoint.sh /etc…" 52 minutes ago Up 50 minutes 0.0.0.0:5000->5000/tcp registry
[root@kolla ~]#
使用curl访问registry,如下:
[root@kolla ~]#
[root@kolla ~]# curl http://192.168.164.129:5000/v2/_catalog
{"repositories":["centos-source-cron"]}
[root@kolla ~]#
可以看到返回结果里面有一个镜像(之前做测试传上去的)
三、上传 镜像至私有仓库
查看本地的镜像,如下:
[root@kolla ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
kolla/centos-source-fluentd pike cfc2b612ceb5 5 weeks ago 746MB
registry latest f32a97de94e1 9 months ago 25.8MB
registry latest f32a97de94e1 9 months ago 25.8MB
为镜像打tag,如下:
[root@kolla ~]#
[root@kolla ~]# docker tag kolla/centos-source-fluentd:pike 192.168.164.129:5000/centos-source-fluentd:v2
[root@kolla ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.164.129:5000/centos-source-fluentd v2 cfc2b612ceb5 5 weeks ago 746MB
kolla/centos-source-fluentd pike cfc2b612ceb5 5 weeks ago 746MB
registry latest f32a97de94e1 9 months ago 25.8MB
registry latest f32a97de94e1 9 months ago 25.8MB
使用docker push上传镜像,如下:
[root@kolla ~]#
[root@kolla ~]# docker push 192.168.164.129:5000/centos-source-fluentd:v2
The push refers to repository [192.168.164.129:5000/centos-source-fluentd]
Get https://192.168.164.129:5000/v2/: http: server gave HTTP response to HTTPS client
错误原因:原因是docker私有仓库服务器,默认是基于https传输的,所以我们需要在客户端192.168.164.129做相关设置,不使用https传输
解决方法如下:
编辑文件:vi /etc/docker/daemon.json,加入以下内容(添加信任):
{
"registry-mirrors": [ "https://registry.docker-cn.com" ],
"insecure-registries": ["192.168.164.129:5000"]
}
重启docker服务:
systemctl restart docker
再次上传,如下:
[root@kolla ~]# docker push 192.168.164.129:5000/centos-source-fluentd:v2
The push refers to repository [192.168.164.129:5000/centos-source-fluentd]
0c311623f7a0: Preparing
aaf22431fda4: Preparing
021e650fd108: Preparing
f82b20c03914: Preparing
a9a24776e712: Preparing
f82b20c03914: Pushed
5da4d7b91205: Pushed
f67ac5c9d811: Pushed
9cc987c573d9: Pushed
877b494a9f30: Pushed
v2: digest: sha256:33aaa750fb78becc78a6b751880d0d52765e1c4ecf9eb03924ce2c1ab376e55d size: 8235
[root@kolla ~]#
查看私有registry,如下:
root@kolla ~]#
[root@kolla ~]# curl http://192.168.164.129:5000/v2/_catalog
{"repositories":["centos-source-cron","centos-source-fluentd"]}
[root@kolla ~]#
多了一个centos-source-fluentd镜像。
获取某个镜像的tag,如下:
[root@kolla ~]#
[root@kolla ~]# curl http://192.168.164.129:5000/v2/centos-source-fluentd/tags/list
{"name":"centos-source-fluentd","tags":["v2"]}