Docker搭建私有镜像仓库的方法

和Mavan的管理一样,Dockers不仅提供了一个中央仓库,同时也允许我们使用registry搭建本地私有仓库。

使用私有仓库有许多优点:

  1. 节省网络带宽,针对于每个镜像不用每个人都去中央仓库上面去下载,只需要从私有仓库中下载即可;
  2. 提供镜像资源利用,针对于公司内部使用的镜像,推送到本地的私有仓库中,以供公司内部相关人员使用。

现在Docker用处越来越多了,所以今天就想着搭建一个私有镜像仓库来维护内部我们自己的镜像。

环境

  1. CentOS 7.x
  2. Docker 1.12.6

安装 docker-distribution

$ sudo yum install -y docker-distribution

$ sudo systemctl enable docker-distribution

$ sudo systemctl start docker-distribution

使用

获取测试镜像

首先从Docker中央仓库获取一个用来测试的容器镜像,这里就使用busyBox来作为测试镜像。

$ sudo docker pull busyBox

$ sudo docker images
REPOSITORY          TAG         IMAGE ID      CREATED       SIZE
docker.io/busyBox       latest       9d7e6df8e5ca    8 hours ago     1.129 MB

标记上传镜像私有镜像

我们这里不对busyBox做任何修改,只是换个名字作为私有镜像。

$ sudo docker tag busyBox:latest localhost:5000/kongxx/mybusyBox:latest
$ sudo docker push localhost:5000/kongxx/mybusyBox:latest

上传完成后可以使用下面命令查看一下

$ curl http://192.168.0.109:5000/v2/kongxx/busyBox/tags/list
{"name":"kongxx/busyBox","tags":["latest"]}

同时我们查看一下本地的镜像列表

$ sudo docker images
REPOSITORY            TAG         IMAGE ID      CREATED       SIZE
localhost:5000/kongxx/mybusyBox  latest       9d7e6df8e5ca    8 hours ago     1.129 MB
docker.io/busyBox         latest       9d7e6df8e5ca    8 hours ago     1.129 MB

测试镜像仓库

为了能访问私有仓库(因为这里是自己测试,所以没有使用https),还需要修改一下Docker配置文件

编辑 /etc/sysconfig/docker 文件,将其中的 OPTIONS 参数加上

--insecure-registry 192.168.0.109:5000

然后重新启动Docker服务

$ sudo systemctl restart docker

为了测试,我们先把原来本地已经有的镜像删除

$ sudo docker rmi docker.io/busyBox
$ sudo docker rmi localhost:5000/kongxx/mybusyBox

然后重新获取镜像,如下:

$ sudo docker pull 192.168.0.109:5000/kongxx/mybusyBox
Using default tag: latest
Trying to pull repository 192.168.0.109:5000/kongxx/mybusyBox ...
latest: Pulling from 192.168.0.109:5000/kongxx/mybusyBox
414e5515492a: Pull complete
Digest: sha256:fbcd856ee1f73340c0b7862201b9c045571d1e357797e8c4c0d02a0d21992b80

输出可以看到已经可以从自己的仓库下载镜像了。

其他

最后说一下,如果要查询私有仓库里有哪些镜像,我还没有找到啥好方法可以一次全部查到,但是可以通过下面的组合命令来查询

首先查询私有仓库上有那些镜像名

$ curl -XGET http://192.168.0.109:5000/v2/_catalog
{"repositories":["kongxx/mybusyBox","mandy/mybusyBox"]}

然后使用下面的命令查看镜像有那些版本

# curl -XGET http://192.168.0.109:5000/v2/<image_name>/tags/list
$ curl -XGET http://192.168.0.109:5000/v2/kongxx/mybusyBox/tags/list
{"name":"kongxx/mybusyBox","tags":["latest"]}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程之家。

相关文章

今天小编给大家分享一下excel图案样式如何设置的相关知识点,...
这篇文章主要讲解了“win10设置过的壁纸如何删除”,文中的讲...
这篇“Xmanager怎么显示远程linux程序的图像”文章的知识点大...
今天小编给大家分享一下xmanager怎么连接linux的相关知识点,...
这篇“如何重置Linux云服务器的远程密码”文章的知识点大部分...
本篇内容介绍了“Linux云服务器手动配置DNS的方法是什么”的...