Docker私有镜像仓库搭建、访问、查询
Docker私有镜像仓库搭建、访问、查询
在使用docker pull命令时,如果不额外指定镜像仓库,默认从docker.io获取镜像文件。
搭建私有docker镜像仓库对定制化镜像的保存,局域网内部镜像获取提供方便。
本文主要介绍:
1.私有镜像仓库的搭建
2.私有镜像仓库提供局域网内其他主机访问
3.查询私有仓库内镜像
0.环境介绍
主机OS | 7.6.1810 |
---|---|
Docker版本 | 1.13.1 |
docker镜像仓库IP | 1.1.1.10/24 |
docker client IP | 1.1.1.11/24 |
1.私有镜像仓库的搭建
1.1.
私有镜像也作为一个容器运行在docker环境中。
直接使用官方registry镜像安装
[root@localhost ~]# docker run -d -p 5000:5000 --restart=always --name myregistry registry Unable to find image 'registry:latest' locally Trying to pull repository docker.io/library/registry ... latest: Pulling from docker.io/library/registry c87736221ed0: Pull complete 1cc8e0bb44df: Pull complete 54d33bcb37f5: Pull complete e8afc091c171: Pull complete b4541f6d3db6: Pull complete Digest: sha256:8004747f1e8cd820a148fb7499d71a76d45ff66bac6a29129bfdbfdc0154d146 Status: Downloaded newer image for docker.io/registry:latest 1f95ed9b5f6d253a7f5266dda7978054cc89481d9cd3de7f50a4359cc1eb160d
1.2.
查看registry容器运行状态
[root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1f95ed9b5f6d registry "/entrypoint.sh /e..." 2 minutes ago Up 2 minutes 0.0.0.0:5000->5000/tcp myregistry
1.3.
从docker.io下载centos镜像
[root@localhost ~]# docker pull centos Using default tag: latest Trying to pull repository docker.io/library/centos ... latest: Pulling from docker.io/library/centos 8ba884070f61: Pull complete Digest: sha256:a799dd8a2ded4a83484bbae769d97655392b3f86533ceb7dd96bbac929809f3c Status: Downloaded newer image for docker.io/centos:latest
[root@localhost ~]# docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/centos latest 9f38484d220f 4 months ago 202 MB docker.io/registry latest f32a97de94e1 4 months ago 25.8 MB
1.4.
给镜像打tag
格式为 仓库地址/镜像名/版本
[root@localhost ~]# docker tag docker.io/centos 127.0.0.1:5000/mycentos/latest [root@localhost ~]# docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE 127.0.0.1:5000/mycentos/latest latest 9f38484d220f 4 months ago 202 MB docker.io/centos latest 9f38484d220f 4 months ago 202 MB docker.io/registry latest f32a97de94e1 4 months ago 25.8 MB
使用docker push上传镜像时,会根据tag识别镜像仓库地址
如不打tag,默认上传到 docker.io 的root用户下, 当然普通用户是没有权限的。 报错如下
[root@localhost ~]# docker push centos Error response from daemon: You cannot push a "root" repository. Please rename your repository to docker.io/<user>/<repo> (ex: docker.io/<user>/centos)
1.5.
成功传至私有仓库
[root@localhost ~]# docker push 127.0.0.1:5000/mycentos/latest The push refers to a repository [127.0.0.1:5000/mycentos/latest] d69483a6face: Pushed latest: digest: sha256:ca58fe458b8d94bc6e3072f1cfbd334855858e05e1fd633aa07cf7f82b048e66 size: 529
2.私有镜像仓库提供局域网内其他主机访问
以上测试是将本地的image文件上传至镜像仓库。如需将镜像仓库提供给局域网内其他主机使用,需要做其他配置。
首先直接尝试从docker client push镜像到镜像仓库,失败。 提示关于HTTPS报错
[root@localhost ~]# docker push 1.1.1.10:5000/centos The push refers to a repository [1.1.1.10:5000/centos] Get https://1.1.1.10:5000/v1/_ping: http: server gave HTTP response to HTTPS client
这是因为docker官网使用HTTPS协议, 默认不允许非 HTTPS 方式推送镜像
此问题有两种方法解决。
- 为私有仓库添加TLS证书,走HTTPS认证。
- 将HTTPS认证改为HTTP认证。
这里主要讲解第二种。
2.1.
修改docker daemon文件, /usr/lib/systemd/system/docker.service
在ExecStart属性中添加私有仓库地址,并设定为HTTP认证
2.2.
reload daemon, 重启docker
[root@localhost ~]# systemctl daemon-reload [root@localhost ~]# systemctl restart docker
2.3.
查看docker状态,可以看到在启动参数中已经添加了私有仓库地址
[root@localhost ~]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2019-07-31 02:03:53 EDT; 46s ago
Docs: http://docs.docker.com
Main PID: 25477 (dockerd-current)
CGroup: /system.slice/docker.service
├─25477 /usr/bin/dockerd-current –add-registry=1.1.1.10:5000 --insecure-registry=1.1.1.10:5000 --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current --default-runtime=docker-runc -…
└─25482 /usr/bin/docker-containerd-current -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --metrics-interval=0 --start-timeout 2m --state-dir /var/run/docker/libcontainerd/conta…
2.4.
再次尝试将centos镜像push到私有仓库,成功。
[root@localhost ~]# docker push 1.1.1.10:5000/centos The push refers to a repository [1.1.1.10:5000/centos] 73d61bf022fd: Pushed 5bbc5831d696: Pushed d5974ddb5a45: Pushed f641ef7a37ad: Pushed d9ff549177a9: Pushed latest: digest: sha256:b1165286043f2745f45ea637873d61939bff6d9a59f76539d6228abf79f87774 size: 1363
2.5.
由于已经将私有镜像仓库添加到docker启动参数中,可以直接使用docker pull命令从私有仓库获取镜像,而不需要指定仓库地址
[root@localhost ~]# docker pull centos Using default tag: latest Trying to pull repository 1.1.1.10:5000/centos ... latest: Pulling from 1.1.1.10:5000/centos Digest: sha256:b1165286043f2745f45ea637873d61939bff6d9a59f76539d6228abf79f87774 Status: Image is up to date for 1.1.1.10:5000/centos:latest
2.6.
尝试pull一个私有仓库中没有的镜像,可以看到docker先检查私有仓库是否有镜像,没有镜像的话转到docker.io下载镜像。 因此, pull来源的优先级是: 本地镜像列表>私有镜像仓库>docker.io
[root@localhost ~]# docker pull busybox Using default tag: latest Trying to pull repository 1.1.1.10:5000/busybox ... Pulling repository 1.1.1.10:5000/busybox Trying to pull repository docker.io/library/busybox ... latest: Pulling from docker.io/library/busybox Digest: sha256:9f1003c480699be56815db0f8146ad2e22efea85129b5b5983d0e0fb52d9ab70 Status: Image is up to date for docker.io/busybox:latest
3.查询私有仓库内镜像
使用curl查询私有镜像仓库内都有哪些镜像
curl <仓库地址>/v2/_catalog
[root@localhost ~]# curl 1.1.1.10:5000/v2/_catalog {"repositories":["centos","mycentos/latest"]}
在镜像仓库主机上使用 docker image ls看到的只是本地的image list, 与镜像仓库不是一个概念
使用docker search 1.1.1.10:5000/centos也会报错。
- 点赞
- 收藏
- 分享
- 文章举报
- docker搭建了私有仓库,却从谷歌下载镜像的问题???
- 【Docker】(4)搭建私有镜像仓库
- 干货,docker私有仓库registry使用oss存储,附registry镜像上传、查询及删除命令
- docker 查询或获取私有仓库(registry)中的镜像的方法
- Docker Registry搭建私有镜像仓库的实现方法
- 使用Harbor搭建Docker私有镜像仓库服务
- 基于 Harbor 搭建 Docker 私有镜像仓库
- 搭建docker镜像私有仓库
- 使用Harbor搭建Docker私有镜像仓库服务
- 详解docker实战之搭建私有镜像仓库 - kurbernetes
- 一文搞定docker创建私有镜像仓库(配置启动http和https方式私有仓库服务,查询、删除私有仓库镜像)
- 使用官方 docker registry 搭建私有镜像仓库及部署 web ui
- 基于 Harbor 搭建 Docker 私有镜像仓库
- 搭建私有docker镜像仓库
- 使用 harbor 搭建 docker 私有镜像仓库
- docker 查询或获取私有仓库(registry)中的镜像
- 详解基于Harbor搭建Docker私有镜像仓库
- 使用docker Registry快速搭建私有镜像仓库
- Docker搭建带有访问认证的私有仓库