CentOS7 Docker搭建私有镜像仓库
简述
docker
中拉取的镜像都是在docker hub
在线存储库中获取的,这个在线存储库里的docker镜像可以由任何用户发布和使用,显然这在某些场景下是不适用的,比如某些互金的隐私项目,或者是公司完全处于内网状态不能访问外网,再或者你想个性化定制某些配置等等等,所以这就需要用到私有存储库了,今天我们就基于registry镜像
搭建属于我们自己的私有仓库。
拉取registry
[root@localhost ~]# docker pull registry Using default tag: latest latest: Pulling from library/registry 79e9f2f55bf5: Pull complete 0d96da54f60b: Pull complete 5b27040df4a2: Pull complete e2ead8259a04: Pull complete 3790aef225b9: Pull complete Digest: sha256:169211e20e2f2d5d115674681eb79d21a217b296b43374b8e39f97fcf866b375 Status: Downloaded newer image for registry:latest docker.io/library/registry:latest [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE registry latest b8604a3fe854 4 months ago 26.2MB
配置私有仓库地址
[root@localhost ~]# vim /etc/docker/daemon.json {"registry-mirrors": ["https://j5wsgox9.mirror.aliyuncs.com"] } { "insecure-registries": ["192.168.0.110:5000"] }
重启docker,加载docker配置
[root@localhost ~]# systemctl restart docker [root@localhost ~]# systemctl daemon-reload
创建容器
[root@localhost ~]# docker run -d -p 5000:5000 --restart always --name registry docker.io/registry 2f73dcf7fc4d53cd18b993f4af80bcf205950b6bba24332869a5bad863713a59 [root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 2f73dcf7fc4d registry "/entrypoint.sh /etc…" 5 seconds ago Up 3 seconds 0.0.0.0:5000->5000/tcp, :::5000->5000/tcp registry
浏览器访问
192.168.0.110:5000/v2/_catalog
这里【】里没有上传有镜像,所以是空的
如果访问不到,尝试关闭防火墙:
systemctl stop firewalld systemctl disable firewalld iptables -F iptables -X iptables -Z iptables-save
如果还是访问不不到,可以重启一下docker
sudo systemctl restart docker
然后重新运行一下容器。
验证上传镜像到私有仓库
使用HelloWorld
镜像进行测试
[root@localhost ~]# docker pull hello-world Using default tag: latest latest: Pulling from library/hello-world 2db29710123e: Pull complete Digest: sha256:2498fce14358aa50ead0cc6c19990fc6ff866ce72aeb5546e1d59caac3d0d60f Status: Downloaded newer image for hello-world:latest docker.io/library/hello-world:latest [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE registry latest b8604a3fe854 4 months ago 26.2MB hello-world latest feb5d9fea6a5 6 months ago 13.3kB
接下来我们使用 push 指令将镜像推送到刚刚搭建的registry中
先给这个镜像打一个新的标签,用于区别。使用docker tag 命令
[root@localhost ~]# docker tag hello-world 192.168.0.110:5000/hello-world:latest [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE registry latest b8604a3fe854 4 months ago 26.2MB 192.168.0.110:5000/hello-world latest feb5d9fea6a5 6 months ago 13.3kB hello-world latest feb5d9fea6a5 6 months ago 13.3kB
如果push遇到这个问题,去修改 vim /usr/lib/systemd/system/docker.service配置文件,在12行位置左右,
在Execstart后面添加 --insecure-registry ip:5000,然后重启docker服务,和配置文件。
[root@localhost ~]# vim /usr/lib/systemd/system/docker.service [Unit] Description=Docker Application Container Engine Documentation=https://docs.docker.com After=network-online.target docker.socket firewalld.service containerd.service Wants=network-online.target Requires=docker.socket containerd.service [Service] Type=notify # the default is not to use systemd for cgroups because the delegate issues still # exists and systemd currently does not support the cgroup feature set required # for containers run by docker ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --insecure-registry 192.168.0.110:5000 ExecReload=/bin/kill -s HUP $MAINPID TimeoutSec=0 RestartSec=2 Restart=always # Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229. # Both the old, and new location are accepted by systemd 229 and up, so using the old location # to make them work for either version of systemd. StartLimitBurst=3 # Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230. # Both the old, and new name are accepted by systemd 230 and up, so using the old name to make # this option work for either version of systemd. StartLimitInterval=60s # Having non-zero Limit*s causes performance problems due to accounting overhead # in the kernel. We recommend using cgroups to do container-local accounting. LimitNOFILE=infinity LimitNPROC=infinity LimitCORE=infinity "/usr/lib/systemd/system/docker.service" 47L, 1748C written
如果出现扯个报错,在/etc/docker/daemon.json下添加私有仓库镜像就好了,然后重启docker,和配置文件
[root@localhost ~]# docker push 192.168.0.110:5000/hello-world:latest The push refers to repository [192.168.0.110:5000/hello-world] Get "http://192.168.0.110:5000/v2/": dial tcp 192.168.0.110:5000: connect: connection refused [root@localhost ~]# systemctl restart docker [root@localhost ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 2f73dcf7fc4d registry "/entrypoint.sh /etc…" 34 minutes ago Exited (2) 14 minutes ago registry [root@localhost ~]# docker start 2f73dcf7fc4d 2f73dcf7fc4d
重新推送
[root@localhost ~]# docker push 192.168.0.110:5000/hello-world:latest The push refers to repository [192.168.0.110:5000/hello-world] e07ee1baac5f: Pushed latest: digest: sha256:f54a58bc1aac5ea1a25d796ae155dc228b3f0e11d046ae276b39c4bf2f13d8c4 size: 525
浏览器访问
可以看到hello-world推送完成
CentOS7 Docker搭建私有镜像仓库相关推荐
- Docker搭建私有镜像仓库
一. 常见镜像仓库服务 镜像仓库(Docker Registry)有公共的和私有的两种形式: 公共仓库:例如Docker官方的Docker Hub,国内也有一些云服务商提供类似于Docker Hub的 ...
- 基于Docker搭建私有镜像仓库
通常我们在docker中拉取的镜像都是在docker hub在线存储库中获取的,这个在线存储库里的docker镜像可以由任何用户发布和使用,显然这在某些场景下是不适用的,比如某些互金的隐私项目,或者是 ...
- 搭建Docker本地私有镜像仓库
在使用Docker service create创建容器时,Docker首先默认从Docker Hub官方去下载镜像,这很不方便,很多时候我们的镜像都是使用Dockerfile自定义私有镜像,不对外公 ...
- Nexus 搭建私有镜像仓库
Nexus 搭建私有镜像仓库 说明 国内网络环境下直接使用默认的 npm 下载资源过慢,所以很多文章中都建议将 npm 的 registry 切换为 淘宝的 npm 镜像,如下 npm config ...
- 一文搞定docker创建私有镜像仓库(配置启动http和https方式私有仓库服务,查询、删除私有仓库镜像)
docker除了使用公共镜像仓库之外,也可以创建私有镜像仓库.对于内部开发.测试.部署环境来说,是很有必要的. 如何创建私有镜像仓库服务呢?当然是以容器的方式啦! 1.拉取官方regis ...
- Docker Registry 私有镜像仓库批量清理镜像
Docker 私有镜像仓库批量清理镜像 前言 在频繁长期使用镜像仓库后,由于镜像仓库清理镜像比较费劲,业内也没有一个比较好的清理方案,官方提供的镜像仓库清理也比较费劲,导致 Docker 镜像仓库越积 ...
- 基于 registry 搭建 Docker 私有镜像仓库
dockerhub: https://registry.hub.docker.com/_/registry 安装命令 docker run -p 5000:5000 -d -v /opt/regist ...
- 搭建Docker私有镜像仓库
一.Docker镜像和容器的区别 Docker的整个生命周期由三部分组成:镜像(image)+容器(container)+仓库(repository) 容器等于镜像加上可读层,容器是由镜像实例化而来的 ...
- Docker 私有镜像仓库的搭建及认证
转自乐字节 DockerHub 为我们提供了很多官方镜像和个人上传的镜像,我们可以下载机构或个人提供的镜像,也可以上传我们自己的本地镜像,但缺点是: 由于网络的原因,从 DockerHub 下载和上传 ...
最新文章
- 惊!史上最全的select加锁分析(Mysql)
- IntelliJ IDEA快捷键总结
- spring中基于XML的AOP配置步骤
- Solr实战(二):索引操作
- php web开发应用教程,PHP-Web 应用程序开发:使用模板_PHP
- 计算机5800怎么开机,神舟5800笔记本怎么进bios
- vb上传文件到MySQL_ASP.NET上传文件到数据库VB版
- Chrome 100发布:全新图标,CPU、内存占用暴降!
- 整古专家之恶意批处理命令
- 问答| 为什么四轮驱动机器人(SSMR)的质心(COM)没有横向分速度vy呢?
- 全网首发:JDK绘制文字:七、使用字体图像进行绘制
- pass 软件_PASS软件非劣效Logrank检验的h1参数如何设置?
- 在word中插入参考文献角标
- opencv warp(扭曲)球面投影的原理
- c语言 大小写 islower,C 库函数 islower() 使用方法及示例
- 抖音seo,抖音优化系统,抖音seo矩阵系统源码技术搭建
- RIoTBoard开发板系列笔记(十二)—— gstreamer + vpu实现视频硬件解码播放
- 领导者应具备的三个能力
- 蓝桥杯 Beaver's Calculator
- 数据挖掘的概念和步骤
热门文章
- 使用Typora书写甘特图
- alertdialog怎么水平排列_网图骗人?别墅挂画怎么挂都不好看?答案在这里
- 西北工业大学计算机基础学什么,计算机基础知识和基本操作(第2版)-西北工业大学.pdf...
- Gitk 查看记录时中文乱码的其中一种设置方式
- 经验总结 | R语言整理数据常用小技巧
- 短信验证码和语音验证码该如何选择?
- MT6739芯片处理器,MT6739套片开发资料汇集下载
- 国科大计算机算法设计与分析陈玉福,中科院陈玉福计算机算法设计与分析期末简答题答案...
- Adobe Flex是什么玩意儿?
- 优雅的在latex中插入MATLAB代码 | 解决MATLAB代码中文乱码问题