搭建私有 Docker 仓库服务器

Docker Hub 是 Docker 官方的公共仓库服务器,用户在 DockerHub 上只能创建一个私有仓库,这对于有些用户是不够用的,而且 DockerHub 服务器的访问速度也是个很大问题,那么我们希望能在自己本地的服务器上创建一个类似于 DockerHub 仓库服务器供团队使用,这也是可以的。

我测试的环境是 Mac OSX 下,已经通过 Boot2Docker 工具安装好 Docker 的环境,通过 命令boot2docker
ip
 可以查看虚拟机的 IP 是 192.168.59.104。那么下面我就在自己虚拟机上搭建一个私有的
Docker 仓库服务器:

安装运行 Docker-Registry

运行官方提供的 registry 镜像,将端口映射到主机的 5000 端口上,其它均使用默认配置:

[email protected] ? ~ ? docker run -d -p 5000:5000 registry
Unable to find image ‘registry:latest‘ locally
6cfde7386ab2: Pull complete
9789d95d9fda: Pull complete
19443e64f223: Pull complete
b329371ab73c: Pull complete
f0daee9a4e8f: Pull complete
a66e50e56475: Pull complete
8ab3d2988df5: Pull complete
5f60fa7ea945: Pull complete
db22a140c899: Pull complete
5b2fff9306bd: Pull complete
511136ea3c5a: Already exists
f3c84ac3a053: Already exists
a1a958a24818: Already exists
9fec74352904: Already exists
d0955f21bf24: Already exists
registry:latest: The image you are pulling has been verified. Important: image verification is a tech preview feature and should not be relied on to provide security.
Status: Downloaded newer image for registry:latest
8fb8e82e61822e593e10b59a4e7bbad18c789b34e3b38942d5b63dccb497ed09

上传镜像到私有仓库

创建好私有仓库之后,我们就可以向该仓库上传镜像,别人也可以从该仓库下载镜像了。

查看本地已有的镜像:

[email protected] ? ~ ? docker images
REPOSITORY                  TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
nginx                       latest              637d3b2f5fb5        4 days ago          93.44 MB
mysql                       latest              0feafece277d        11 days ago         282.9 MB
wordpress                   latest              f90659c8fdb9        2 weeks ago         451.5 MB
ubuntu                      latest              d0955f21bf24        4 weeks ago         188.3 MB
google/golang               latest              3cc1d7ae0e9c        11 weeks ago        611.3 MB
hello-world                 latest              e45a5af57b00        3 months ago        910 B

通过 docker tage 命令将 hello-world 这个镜像标记为 192.168.59.104:5000/hello-world之后,再
push 到该镜像到私有仓库:

[email protected] ? ~ ? docker tag hello-world 192.168.59.104:5000/hello-world
[email protected] ? ~ ? docker push 192.168.59.104:5000/hello-world
FATA[0000] Error: v1 ping attempt failed with error: Get https://192.168.59.104:5000/v1/_ping: dial tcp 192.168.59.104:5000: connection refused. If this private registry supports only HTTP or HTTPS with an unknown CA certificate, please add `--insecure-registry 192.168.59.104:5000` 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.59.104:5000/ca.crt

发现报错,使用 SO上类似问题 的解决方法可以解决上面的错误:

To use the --insecure-registry option,
add it to the file /var/lib/boot2docker/profile inside
the boot2docker VM. You can get into the VM with boot2docker
ssh
. The file contents should look like:

EXTRA_ARGS="--insecure-registry
REGISTRY_IP:PORT"
 You will then need to restart boot2docker (e.g. boot2docker
restart
).

步骤如下:

  1. 使用 boot2docker ssh 登陆到 boot2docker
    虚拟机
  2. 修改 /var/lib/boot2docker/profile 文件,向该文件中增加一行:EXTRA_ARGS="--insecure-registry
    192.168.59.104:5000"
  3. 退出该虚拟机并使用命令 boot2docker restart 重启
    boot2docker

完成重启之后,将私有仓库服务器运行起来,并 push hello-world 到该仓库:

[email protected] ? ~ ? docker run -d -p 5000:5000 registry
4935607095a22655da1ef91feb6f569264a50529cb8d594d520fe62da81250db
[email protected] ? ~ ? docker push 192.168.59.104:5000/test
The push refers to a repository [192.168.59.104:5000/test] (len: 1)
Sending image list
Pushing repository 192.168.59.104:5000/test (1 tags)
511136ea3c5a: Image successfully pushed
31cbccb51277: Image successfully pushed
e45a5af57b00: Image successfully pushed
Pushing tag for rev [e45a5af57b00] on {http://192.168.59.104:5000/v1/repositories/test/tags/latest}

使用 Docker 的 RESTful API 可以查看仓库服务器中的镜像:

[email protected] ? ~ ? curl http://192.168.59.104:5000/v1/search
{"num_results": 1, "query": "", "results": [{"description": "", "name": "library/hello-world"}]}%

表示 hello-world 镜像已成功长传至私有仓库服务器了。

从私有仓库中下载、搜索镜像

其他机器可以从私有仓库服务器上下载、搜索镜像等,与从 Docker Hub 上操作无异,只不过需要指出仓库的位置,如:

[email protected] ? ~ ? docker rmi -f 192.168.59.104:5000/hello-world
Untagged: 192.168.59.104:5000/hello-world:latest
Deleted: e45a5af57b00862e5ef5782a9925979a02ba2b12dff832fd0991335f4a11e5c5
Deleted: 31cbccb51277105ba3ae35ce33c22b69c9e3f1002e76e4c736a2e8ebff9d7b5d
[email protected] ? ~ ? docker search 192.168.59.104:5000/hello-world
NAME                  DESCRIPTION   STARS     OFFICIAL   AUTOMATED
library/hello-world                 0
[email protected] ? ~ ? docker pull 192.168.59.104:5000/hello-world
Pulling repository 192.168.59.104:5000/hello-world
e45a5af57b00: Download complete
511136ea3c5a: Download complete
31cbccb51277: Download complete
Status: Downloaded newer image for 192.168.59.104:5000/hello-world:latest


参考资料: http://dockerpool.com/static/books/docker_practice/repository/local_repo.html

时间: 2024-08-26 05:33:47

搭建私有 Docker 仓库服务器的相关文章

Nexus Repository Manager 搭建私有docker仓库

使用容器安装Nexus3 1.下载nexus3的镜像: docker pull sonatype/nexus3 2.使用镜像启动一个容器: docker run -d --name nexus  --restart=always -p 5000:5000 -p 8081:8081 sonatype/nexus3 注:5000端口是用于镜像仓库的服务端口   8081 端口是nexus的服务端口 3.启动之后我们就可以通过http://服务器IP:8081访问. 默认账号密码为admin/admi

使用 Nexus Repository Manager 搭建私有docker仓库

docker pull sonatype/nexus3 2.使用镜像启动一个容器: docker run -d --name nexus  --restart=always -p 5000:5000 -p 8081:8081 sonatype/nexus3 注:5000端口是用于镜像仓库的服务端口   8081 端口是nexus的服务端口 3.启动之后我们就可以通过http://服务器IP:8081访问. 默认账号密码为admin/admin123 通过浏览器访问Nexus: http://服务

在Kubernetes集群的etcd上搭建私有docker仓库

[[email protected] ~]# yum groupinstall -y "Development Tools" [[email protected] ~]# yum -y install epel-release [[email protected] ~]# yum -y install python-dev* libevent-dev* python-pip* openssl-devel xz-devel libffi-dev* [[email protected] ~

【Docker】(4)搭建私有镜像仓库

[Docker](4)搭建私有镜像仓库 说明 1. 这里是通过阿里云,搭建Docker私有镜像仓库. 2. 这里打包的镜像是从官网拉下来的,并不是自己项目创建的新镜像,主要测试功能 一.搭建过程 首先进入阿里云创建镜像仓库: https://dev.aliyun.com/search.html-->点击管理中心(初次使用会提示开通,然后设置密码) 然后创建命名空间和镜像仓库: 有关docker拉取和推送指令,点击上图的中管理,就能看到. 1.登录阿里云 docker login [email p

用registry快速搭建私有镜像仓库

1.背景 在 Docker 中,当我们执行 docker pull xxx 的时候,可能会比较好奇,docker 会去哪儿查找并下载镜像呢? ?它实际上是从 registry.hub.docker.com 这个地址去查找,这就是Docker公司为我们提供的公共仓库,上面的镜像,大家都可以看到,也可以使用.所以,我们也可以带上仓库地址去拉取镜像,如:docker pull registry.hub.docker.com/library/alpine,不过要注意,这种方式下载的镜像的默认名称就会长一

实验:安装centos-6,开启网卡,搭建私有yum仓库

安装red hat centos -6的详细步骤,包含开启网卡.搭建私有yum仓库 1.新建虚拟机,选择自定义安装,下一步 2.虚拟机硬件兼容性以已安装的vmware 为准,不知道的默认即可,然后点击下一步 3.选择稍后安装系统,然后下一步 4.操作系统linux,版本找到red hat linux 6 64 位,选择好点击下一步 5.虚拟机名称自己起,根据自己的习惯来设置 位置不要安装在c盘,有固态的安在固态上,重新创建一个文件夹去指定安装位置,便于以后的管理,即虚拟机的删除.移动.复制:选择

Docker——Registry搭建私有镜像仓库

前言 在 Docker 中,当我们执行 docker pull xxx 的时候,它实际上是从 registry.hub.docker.com 这个地址去查找,这就是Docker公司为我们提供的公共仓库,上面的镜像,大家都可以看到,也可以使用. 所以,我们也可以带上仓库地址去拉取镜像,如:docker pull jenkins 在公司中使用 Docker,我们不可能把商业项目上传到公共仓库中,所以要搭建私有仓库. 1.部署仓库 准备1台安装好docker的服务器 (主机名为registry):do

使用docker Registry快速搭建私有镜像仓库

当我们执行docker pull xxx的时候,docker默认是从registry.docker.com这个地址上去查找我们所需要的镜像文件,然后执行下载操作.这类的镜像仓库就是docker默认的公共仓库,所有人都可以直接查看或下载.使用,但是呢,基于网络原因,下载速度有限制比较慢.因此,我们在公司内部内网环境中使用dokcer,一般不会将镜像文件上传到公网公共库中.但内部共享使用就是个问题,所以,私有仓库就由此产生了. 什么是私有仓库? 私有仓库,就是本地(内网环境)组建的一个与公网公共库功

使用Nexus搭建私有Nuget仓库

前言 Nuget是ASP .NET Gallery的一员,是免费.开源的包管理工具,专注于在.Net / .Net Core应用开发过程中第三方组件库的管理,相对于传统单纯的dll引用要方便.科学得多.其中nuget.org是最著名的Nuget公开库,但是企业内部开发的(业务)公共组件不可能都往公开库上传,所以,企业内部需要一个私有的Nuget仓库来支持.虽然微软有提供的Nuget Server,但Nuget Server用起来并不那么顺手,或者说感觉有点low.因此,本文将介绍Nexus搭建的