美文网首页docker
docker搭建私有仓库

docker搭建私有仓库

作者: 刘翊扬 | 来源:发表于2022-09-27 19:36 被阅读0次

运行 registry 镜像

安装 Docker 后,可以通过官方提供的 registry 镜像来简单搭建一套本地私有仓库环境:
查看官方文档:https://hub.docker.com/_/registry

注意:当前机器是centos7, ip 是 192.168.245.133

$ docker run -d -p 5000:5000 --restart always --name registry registry:2

创建私有镜像

$ docker pull ubuntu
$ docker tag ubuntu localhost:5000/ubuntu
# 本机ip是192.168.245.133。为什么不用ip,后面会说
$ docker push localhost:5000/ubuntu

查看镜像

$ docker images
localhost:5000/ubuntu                latest              ba6acccedd29        11 months ago       72.8MB

查看镜像仓库中的镜像

# 列出所有镜像
$ curl http://localhost:5000/v2/_catalog
{"repositories":["ubuntu"]}

# 列出镜像的所有标签
$ curl http://localhost:5000/v2/ubuntu/tags/list
{"name":"ubuntu","tags":["latest"]}

此时我们可以在另外一台机器(192.168.124.132)来拉去下这个镜像

[root@192 ~]# docker pull 192.168.245.133:5000/ubuntu
Using default tag: latest
Error response from daemon: Get "https://192.168.245.133:5000/v2/": http: server gave HTTP response to HTTPS client

遇到上面错误,我们需要修改下 /etc/docker/daemon.json配置

{
"insecure-registries":["192.168.245.133:5000"],
"registry-mirrors": ["https://9fgss2yh.mirror.aliyuncs.com"]
}

配置 insecure-registries(不安全的注册地址), 加上需要镜像仓库地址

修改之后重启下docker

systemctl restart docker

重启之后,重新拉取就可以了

[root@192 ~]# docker pull 192.168.245.133:5000/ubuntu
Using default tag: latest
latest: Pulling from ubuntu
7b1a6ab2e44d: Already exists
Digest: sha256:7cc0576c7c0ec2384de5cbf245f41567e922aab1b075f3e8ad565f508032df17
Status: Downloaded newer image for 192.168.245.133:5000/ubuntu:latest
192.168.245.133:5000/ubuntu:latest

Q: push到本地仓库为啥使用localhost,能使用本地ip吗?

A:当然可以使用本地ip

# 当前机器ip 192.168.245.133
[root@192 ~]# docker pull 192.168.245.133:5000/ubuntu:latest
Error response from daemon: Get https://192.168.245.133:5000/v2/: http: server gave HTTP response to HTTPS client

可以发现直接push会报错,报错跟上面的报错内容一样

此时会把本机的ip地址当成不安全的ip,所以push不上去,配置下,允许本机不安全的ip注册

配置方式跟上面一样,将本机的注册地址加到insecure-registries 配置里面即可

{
"insecure-registries":["192.168.245.133:5000"],
"registry-mirrors": ["https://9fgss2yh.mirror.aliyuncs.com"]
}

然后重启docker

[root@192 ~]# docker pull 192.168.245.133:5000/ubuntu:latest
latest: Pulling from ubuntu
Digest: sha256:7cc0576c7c0ec2384de5cbf245f41567e922aab1b075f3e8ad565f508032df17
Status: Downloaded newer image for 192.168.245.133:5000/ubuntu:latest

此时就push成功了

运行 docker-registry-web 镜像

可参考:https://hub.docker.com/r/hyper/docker-registry-web

$ docker run -it -p 5001:8080 --name registry-web -d --restart always --link registry -e REGISTRY_URL=http://registry:5000/v2 -e REGISTRY_NAME=localhost:5000 hyper/docker-registry-web

然后访问5001端口:http://192.168.245.133:5001/

1999224-20220925113643860-1213945951.png

相关文章

  • Docker

    构建镜像仓库 Docker运行java程序 1.1.6 搭建docker私有仓库 新建私有仓库 1.2.1 数据挂...

  • 5.私有与公有镜像仓库

    一. 搭建私有镜像仓库 Docker Hub作为Docker默认官方公共镜像;如果想自己搭建私有镜像仓库,官方也提...

  • Docker

    一、Docker 私有仓库搭建 环境centos 6 192.168.1.2 Docker 仓库 192.168....

  • k8s学习笔记-5-私有harbor

    5 创建docker私有仓库 使用node5节点搭建harbor私有仓库 harbor仓库依赖docker和doc...

  • Docker搭建私有仓库之Harbor

    Docker搭建私有仓库之Harbor Harbor Harbor是构建企业级私有docker镜像的仓库的开源解决...

  • Docker之八私有仓库

    个人专题目录 Docker 私有仓库 1. 私有仓库搭建 2. 将镜像上传至私有仓库 3. 从私有仓库拉取镜像

  • 搭建docker私有仓库(3)

    至于为什么搭建docker私有仓库,原因很简单,把项目放到docker公有仓库,或者是阿里云的docker仓库,是...

  • Docker私有仓库

    一、Docker私有仓库搭建与配置 1、拉取私有仓库镜像 2、启动私有仓库容器 3、打开浏览器输入地址http:/...

  • docker container monitor

    原文:利用TICK搭建Docker容器可视化监控中心 前言 前面已经搭建了私有docker仓库以及用docker-...

  • Harbor搭建私有Docker仓库

    前言:搭建私有docker仓库,方便部署扩展我们服务... ⚠️必须安装docker(1.10+)和docker-...

网友评论

    本文标题:docker搭建私有仓库

    本文链接:https://www.haomeiwen.com/subject/egqqartx.html