Linux中搭建 Docker私有仓库

私有镜像仓库是指部署在公司或组织内部,用于自身应用Docker镜像存储、分发的镜像仓库。在构建公司内部使用的自动化发布系统的过程中,从安全的角度出发,应用的打包镜像一般情况下只会被存储在私有镜像仓库中。

1、下载registry镜像

[root@localhost ~]# docker pull registry
Using default tag: latest
latest: Pulling from library/registry
486039affc0a: Pull complete
ba51a3b098e6: Pull complete
8bb4c43d6c8e: Pull complete
6f5f453e5f2d: Pull complete
42bc10b72f42: Pull complete
Digest: sha256:7d081088e4bfd632a88e3f3bcd9e007ef44a796fddfe3261407a3f9f04abe1e7
Status: Downloaded newer image for registry:latest
docker.io/library/registry:latest

2、生成registry容器,开放5000端口

[root@localhost ~]# docker create -it registry /bin/bash
fd51aa59dc5cea7b589d0403e562cb8f0098c3a8a7da239572dd5bfd9423ec96
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fd51aa59dc5c registry "/entrypoint.sh /bin…" 10 seconds ago Created optimistic_saha
#建议直接执行下面的这个命令,因为笔者遇到start这个容器发现退出的状态码非0(后面解决了,使用/bin/sh环境即可)
[root@localhost ~]# docker run -d -p 5000:5000 -v /data/registry:/tmp/registry registry
ceb498d622ab743fc858a993e3870f9831e20436cb71f7225215f1f0899571f1
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ceb498d622ab registry "/entrypoint.sh /etc…" 2 seconds ago Up 2 seconds 0.0.0.0:5000->5000/tcp strange_swanson

docker run -d -p 5000:5000 -v /data/registry:/tmp/registry registry命令的解释:

-d ——守护进程

-v ——数据卷设置{/data/registry表示的宿主机系统中的一个绝对路径,没有的时候会自动创建,/tmp/registry表示容器内部的目录}

#宿主机目录

[root@localhost ~]# ls /
bin boot data dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
[root@localhost ~]# ls /data/
registry

#容器内部目录

[root@localhost ~]# docker exec -it ceb498d622ab /bin/sh# ls /
bin etc media root srv usr
dev home mnt run sys var
entrypoint.sh lib proc sbin tmp
/ # ls tmp/
registry

3、客户端设置daemon.json文件 (指定私有仓库位置)

[root@localhost ~]# vim /etc/docker/daemon.json

{
"insecure-registries": ["20.0.0.149:5000"], #将本地服务器作为私有仓库位置
"registry-mirrors": ["https://5m9y9qbl.mirror.aliyuncs.com"]
}
[root@localhost ~]# systemctl restart docker

4、创建本地的镜像标签

[root@localhost ~]# docker pull httpd
Using default tag: latest
latest: Pulling from library/httpd
123275d6e508: Pull complete
e984dd982a6e: Pull complete
963280e5cf81: Pull complete
6faf90d050b2: Pull complete
962b56984bb0: Pull complete
Digest: sha256:d5dc0d279039da76a8b490d89a5c96da83a33842493d4336b42ccdfbd36d7409
Status: Downloaded newer image for httpd:latest
docker.io/library/httpd:latest

[root@localhost ~]# docker tag httpd:latest 20.0.0.149:5000/httpd

5、上传镜像

[root@localhost ~]# docker push 149:5000/httpd
The push refers to repository [149:5000/httpd]
An image does not exist locally with the tag: 149:5000/httpd
[root@localhost ~]# docker push 20.0.0.149:5000/httpd
The push refers to repository [20.0.0.149:5000/httpd]
9dabb51b1ca2: Pushed
4621e8a6d1da: Pushed
e728c649bc91: Pushed
1a935e59aa8a: Pushed
b60e5c3bcef2: Pushed
latest: digest: sha256:8f10edef61246c6c142a87304d4ffa68298662ecb619776e4e9817d06ec5f567 size: 1367
[root@localhost ~]# curl -XGET http://20.0.0.149:5000/v2/_catalog
{"repositories":["httpd"]}
#有上面的结果表示上传成功

6、下载镜像测试

[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
httpd latest bdc169d27d36 Less than a second ago 166MB
20.0.0.149:5000/httpd latest bdc169d27d36 Less than a second ago 166MB
registry latest 708bc6af7e5e 2 months ago 25.8MB
[root@localhost ~]# docker rmi bdc169d27d36
Error response from daemon: conflict: unable to delete bdc169d27d36 (must be forced) - image is referenced in multiple repositories
[root@localhost ~]# docker rmi bdc169d27d36 -f
Untagged: 20.0.0.149:5000/httpd:latest
Untagged: 20.0.0.149:5000/httpd@sha256:8f10edef61246c6c142a87304d4ffa68298662ecb619776e4e9817d06ec5f567
Untagged: httpd:latest
Untagged: httpd@sha256:d5dc0d279039da76a8b490d89a5c96da83a33842493d4336b42ccdfbd36d7409
Deleted: sha256:bdc169d27d36e2438ec8452c7dd7a52a05561b5de7bef8391849b0513a6f774b
Deleted: sha256:6535aa332fb72ca508f550fef8ffb832d4c6bc72a48720b42659e10d47668181
Deleted: sha256:c7bce1fab718a11501a672c895a729b1fdf8099d00fe152bef8c2534ee455976
Deleted: sha256:75b6b2392924b062257ed97e5c2f3aa9f50a922b94c3f7c342d0aed2370e8bec
Deleted: sha256:267e2020b1bd0b182eb02d1a0f3e2f72efc542890ef6159ed9c3570322608de0
Deleted: sha256:b60e5c3bcef2f42ec42648b3acf7baf6de1fa780ca16d9180f3b4a3f266fe7bc
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry latest 708bc6af7e5e 2 months ago 25.8MB
[root@localhost ~]#

测试:

[root@localhost ~]# docker pull 20.0.0.149:5000/httpd
Using default tag: latest
latest: Pulling from httpd
123275d6e508: Pull complete
e984dd982a6e: Pull complete
963280e5cf81: Pull complete
6faf90d050b2: Pull complete
962b56984bb0: Pull complete
Digest: sha256:8f10edef61246c6c142a87304d4ffa68298662ecb619776e4e9817d06ec5f567
Status: Downloaded newer image for 20.0.0.149:5000/httpd:latest
20.0.0.149:5000/httpd:latest
[root@localhost ~]#

拉取成功并且拉取镜像的速度很快。

最后给出上面出现的状态码错误的问题具体解决:

Linux Docker私有仓库搭建教程Linux Docker私有仓库搭建教程

原创文章,作者:晴川运维,如若转载,请注明出处:https://baike.qcidc.com/9511.html

(0)
晴川运维晴川运维
上一篇 2025年6月17日
下一篇 2025年6月17日

相关推荐

  • SVN版本回退

    SVN是一款版本控制工具。相对于GitHub而言,SVN在使用上更为简化些,本篇文章重点为大家讲解一下SVN版本回退。 当我们想放弃对文件的修改,可以使用 SVN revert 命…

    Linux系统 2025年6月21日
  • Mariadb中聚合函数和分组函数具体使用方法

    聚合函数能对集合中的一组数据进行计算,并返回单个计算结果,分组函数通过一定的规则将一个数据集划分为若干个小的区域,然后针对若干个小区域进行统计汇总,般用于对查询结果分组统计,常与聚…

    Linux系统 2025年6月13日
  • 简单讲解一下HBase工作原理

    1 HBase简介 HBase是一个高可靠性、高性能、面向列、可伸缩的分布式存储系统,利用HBase技术可在廉价PC Server上搭建大规模结构化的存储集群。HBase的目标是存…

    Linux系统 2025年6月8日
  • 使用GitHub搭建专属的服务器

    现在固定公网IP资源稀缺,虽然说IPv6已经开始使用,但是用的人并不多,大部分用的都是IPv4,想要搞一个自己网站,首先就是需要一个固定的公网IP,但是每年却需要缴纳不少的mone…

    Linux系统 2025年6月8日
  • 分享一下git使用小技巧

    Git是一个开源的分布式版本控制系统,用以有效、高速的处理从很小到非常大的项目版本管理。Git 是 Linus Torvalds 为了帮助管理 Linux 内核开发而开发的一个开放…

    Linux系统 2025年6月20日
  • RHEL7 or CentOS7重设系统密码

    我们有时会忘记linux系统的root密码,有的人不会重置密码只能重置系统了,本篇文章重点为大家讲解一下RHEL7 or CentOS7重设系统密码具体方法。 介绍 目的 在 RH…

    Linux系统 2025年6月8日
  • 搭建Kubernetes具体流程(上)

    Kubernetes(k8s)是自动化容器操作的开源平台,这些操作包括部署,调度和节点集群间扩展。如果你曾经用过Docker容器技术部署容器,那么可以将Docker看成Kubern…

    Linux系统 2025年6月14日
  • 细说SQLite中表达式

    SQLite是一种C语言库,它实现了一个 小型, 快速, 自包含, 高可靠性, 功能齐全的SQL数据库引擎。SQLite是世界上最常用的数据库引擎。SQLite内置于所有手机和大多…

    Linux系统 2025年6月8日
  • Linux中进程通信方法

    每个进程各自有不同的用户地址空间,任何一个进程的全局变量在另一个进程中都看不到,所以进程之间要交换数据必须通过内核,在内核中开辟一块缓冲区,进程1把数据从用户空间拷到内核缓冲区,进…

    Linux系统 2025年6月11日
  • 使用date 和 bash将日期进行倒计时

    需要知道重要事件发生前有多少天吗?让 Linux bash 和 date 命令可以帮助你!随着即将来临的重要假期,你可能需要提醒你还要准备多久。幸运的是,你可以从date 命令获得…

    Linux系统 2025年6月8日

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注