Docker | docker 私有镜像仓库的安装和使用

Docker registry 的作用

我们通常使用的 docker 镜像,都是在 docker hub 上面拉取的,配置的国内镜像也是复制了一份 docker hub 上面的镜像,如果我们有的隐私项目不想对外共享,或者公司内部,没有连接外网,这时就非常的需要 docker 私有镜像仓库,我们可以配置一个镜像仓库专门为自己或者公司服务。

Docker registry 安装

	# 安装 docker registry 最新镜像
	docker pull registry

image-20220107160834856

	# 运行容器
	docker run -d -p 5000:5000 --name=registry registry

image-20220107160959227

安装成功!登录http://47.100.240.146:5000/v2/_catalog IP地址:5000/v2/_catalog查看仓库中的镜像

image-20220107161058882

确保仓库的宿主机 5000 端口打开,可以用 telnet + IP + 端口号测试

image-20220107161418571

如果无法访问,可以尝试关闭防火墙:

	# 关闭防火墙
	systemctl stop firewalld
	# 重启 docker 服务
	systemctl restart docker

连接docker registry 配置

在需要连接私有镜像的主机上配置

创建配置文件

{
	"insecure-registries": ["47.100.240.146:5000"]
}

如果有多个镜像地址,直接另起一行进行添加

重启docker 服务

	systemctl restart docker

测试

	# 拉取 hello-world 测试镜像
	docker pull hello-world

image-20220107162134994

	# 为镜像打标记
	docker tag hello-world:latest 47.100.240.146:5000/hello-world:latest

image-20220107162417077

	# 推送镜像
	docker push 47.100.240.146:5000/hello-world:latest

查看镜像仓库的网页:

image-20220107162525717

	# 删除刚刚打标记的镜像,重新从镜像仓库中拉取新的镜像
	docker pull 47.100.240.146:5000/hello-world:latest
	# 格式:docker pull IP:POST/镜像名:版本号


关注公众号,随时获取最新资讯

细节决定成败!
个人愚见,如有不对,恳请斧正!

posted @ 2022-01-07 16:30  一点浩然气~  阅读(294)  评论(0编辑  收藏  举报