Docker创建私有Registry

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/m0_37886429/article/details/83269742

一、从github上下载registry镜像

[root@localhost ~]# docker pull registry

二、创建Docker Registry

[root@localhost ~]# docker run -d -v /home/registry:/var/lib/registry -p 5000:5000 --restart=always --privileged=true --name pirvi_registry registry

#参数说明:
-v 将仓库存放于容器内的/var/lib/registry目录下,指定本地目录挂载到容器
-p 5000:5000 端口映射
--restart=always 在容器退出时总是重启容器,主要应用在生产环境
--privileged=true 在Centos7中的安全模块selinux把权限禁掉了,参数给容器加特权,不加上传镜像会报权限错误OSError: [Errno 13] Permission denied: ‘/tmp/registry/repositories/liibrary’)或者(Received unexpected HTTP status: 500 Internal Server Error)错误
--name registry 指定容器的名称

三、创建镜像

1、镜像命名规范

地址/目录/镜像名称:版本


地址一般为 IP:PORT 形式

2、构建镜像
推荐使用DOCKERFILE

[root@localhost ~]# cat Dockerfile 
FROM centos 
MAINTAINER admin <[email protected]>
ENV TZ "Asia/Shanghai"
RUN rpm -ivh http://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
EXPOSE 2000
CMD ['--help']

#构建
[root@localhost ~]# docker build -t 192.168.16.191:5000/test/mycentos:0.0.1 .

三、将镜像推送到私有仓库

[root@localhost ~]# docker push 192.168.16.191:5000/test/mycentos:0.0.1

在这里插入图片描述

将镜像删除后,从私有registry中pull

在这里插入图片描述

四、遇到的问题

Get https://192.168.16.191:5000/v1/_ping: http: server gave HTTP response to HTTPS client

解决方法:
1、首先在docker的主配置文件中添加

[root@localhost ~]# cat /etc/default/docker 
DOCKER_OPTS="--insecure-registry 192.168.16.191:5000"

2、其次修改 daemon.json 文件

[root@localhost ~]# cat /etc/docker/daemon.json 
{
"registry-mirrors": [
"https://2lqq34jg.mirror.aliyuncs.com",
"https://pee6w651.mirror.aliyuncs.com",
"https://registry.docker-cn.com",
"http://hub-mirror.c.163.com"
],
"dns": ["8.8.8.8","8.8.4.4"],
"insecure-registries":["192.168.16.191:5000"]
}

3、重启 docker 服务

[root@localhost ~]#  systemctl restart docker

猜你喜欢

转载自blog.csdn.net/m0_37886429/article/details/83269742