首页 技术 正文
技术 2022年11月15日
0 收藏 646 点赞 2,542 浏览 3114 个字

## 准备工作

用到的工具, Xshell5, Xftp5, docker.io/registry:latest镜像

关于docker的安装和设置加速, 请参考这篇博文centos7系统下 docker 环境搭建

参考之前的博文, 设置完加速后, 执行docker pull registry命令, 下载docker.io/registry官方镜像

## 启动registry镜像

启动docker.io/registry容器, 如果tag是latest, 可以忽略不写

docker run -d -p : --restart=always --name local_registry docker.io/registry:latest

-d 后台运行
-p 端口映射, 宿主机80端口映射给容器的5000端口
–restart=always 容器意外关闭后, 自动重启 (如果重启docker服务, 带这个参数的, 能自动启动为Up状态, 不带这个的,不会自动启动)
–name 给容器起个名字, 可以根据这个名字去停止/启动/删除容器

## 配置端口开放

```
[root@localhost docker]# firewall-cmd --zone=public --add-port=80/tcp --permanent
success
[root@localhost docker]# firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: eth0
sources:
services: dhcpv6-client ssh
ports:
protocols:
masquerade: no
forward-ports:
sourceports:
icmp-blocks:
rich rules: [root@localhost docker]# firewall-cmd --reload
success
[root@localhost docker]# firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: eth0
sources:
services: dhcpv6-client ssh
ports: 80/tcp
protocols:
masquerade: no
forward-ports:
sourceports:
icmp-blocks:
rich rules:
```

配置端口开放之后, 需要执行firewall-cmd –reload才能生效

## 重命名镜像

[root@localhost docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
repos_local/zookeeper 0.0. bdb481b4f17a days ago 541.5 MB

repos_local/zookeeper 是上篇博文介绍的使用Dockerfile文件创建的镜像, 重命名

docker tag repos_local/zookeeper:0.0. 192.168.199.131/repos_local/zookeeper:latest

docker tag 原镜像名:tag 新镜像名:tag

docker images 查看镜像名称是否更改正确

[root@localhost docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.199.131/repos_local/zookeeper latest bdb481b4f17a days ago 541.5 MB

## 推送镜像

docker push 192.168.199.131/repos_local/zookeeper:latest
如果提示以下错误, 说明没有把搭建的registry加入可信任的列表里面, 如果有https域名或者能创建.crt证书, 那么可以忽略以下步骤

Error response from daemon: invalid registry endpoint https://192.168.199.131/v0/: unable to ping registry endpoint https://192.168.199.131/v0/
v2 ping attempt failed with error: Get https://192.168.199.131/v2/: dial tcp 192.168.199.131:443: no route to host
v1 ping attempt failed with error: Get https://192.168.199.131/v1/_ping: dial tcp 192.168.199.131:443: no route to host. If this private registry supports only HTTP or HTTPS with an unknown CA certificate, please add `--insecure-registry 192.168.199.131` to the daemon's arguments. In the case of HTTPS, if you have access to the registry's CA certificate, no need for the flag; simply place the CA certificate at /etc/docker/certs.d/192.168.199.131/ca.crt

解决方法:

只针对centos7下 Docker version 1.12.5, build 047e51b/1.12.5版本有效, 其它版本没做过测试

vi /etc/sysconfig/docker

注意--insecure-registry 192.168.199.131插入的位置
# Modify these options if you want to change the way the docker daemon runs
OPTIONS='--selinux-enabled --log-driver=journald --signature-verification=false --insecure-registry 192.168.199.131'
if [ -z "${DOCKER_CERT_PATH}" ]; then
DOCKER_CERT_PATH=/etc/docker
fi

重启docker服务
systemctl restart docker.service

重新执行docker push 192.168.199.131/repos_local/zookeeper:latest , 这次应该就能成功了

## 查看镜像仓库

[root@localhost docker]# curl 192.168.199.131/v2/_catalog
{"repositories":["repos_local/zookeeper"]}
[root@localhost docker]# curl 192.168.199.131/v2/repos_local/zookeeper/tags/list
{"name":"repos_local/zookeeper","tags":["latest"]}

至于镜像的删除, 目前还没找到一个好的解决方法, 如有建议请留言

如需帮助可向我发起QQ聊天发起QQ聊天

友情赞助

如果您喜欢此文,感觉对您工作有帮助,预期领导会给您涨工资,不妨小额赞助一下,让我有动力继续努力。

赞助方式:打开支付宝App,使用“扫一扫”付款,付款码见下图,别忘了付款留言哦!

centos7系统下搭建docker本地镜像仓库
或使用微信, 不用加好友就能付款
centos7系统下搭建docker本地镜像仓库

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,036
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,522
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,370
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,151
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,784
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,866