Docker私有仓库搭建

TreSBO 8年前
   <pre>  <code class="language-haskell"># 环境  系统 Linux 3.10.0-123.9.3.el7.x86_64 CentOS 7.0.1406 (Core)  Docker 1.12.0, build 8eab29e</code></pre>    <h3><strong>1、获取镜像</strong></h3>    <p>私有仓库以容器的形式运行,需要使用官方的 registry 镜像。</p>    <pre>  <code class="language-haskell">$ docker pull registry    Using default tag: latest  latest: Pulling from library/registry  3690ec4760f9: Pull complete   930045f1e8fb: Pull complete   feeaa90cbdbc: Pull complete   61f85310d350: Pull complete   b6082c239858: Pull complete   Digest: sha256:1152291c7f93a4ea2ddc95e46d142c31e743b6dd70e194af9e6ebe530f782c17  Status: Downloaded newer image for registry:latest</code></pre>    <h3><strong>2、通过registry镜像启动一个容器</strong></h3>    <pre>  <code class="language-haskell">$ docker run -d -p 5000:5000 -v `pwd`/data:/var/lib/registry --restart=always --name registry registry</code></pre>    <p>可以看到我们启动了一个容器,地址为 0.0.0.0:5000 :</p>    <pre>  <code class="language-haskell">$ docker ps  CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES  80abb3f86a78        registry            "/entrypoint.sh /etc/"   22 minutes ago      Up 11 minutes       0.0.0.0:5000->5000/tcp   registry</code></pre>    <h3><strong>3、测试</strong></h3>    <p>私有仓库已经在服务器以容器的形式运行起来了。我们只需要把已有的镜像打上合适的标签就行了。</p>    <p>看个示例:</p>    <pre>  <code class="language-haskell">$ pull registry.aliyuncs.com/acs-sample/mysql</code></pre>    <p>其中 registry.aliyuncs.com 是注册服务器地址, acs-sample/mysql 是仓库名,所有者是 acs-sample ,没有指定镜像标签,则默认是 latest 。</p>    <p>同样的,我们的私有仓库也有注册服务器地址,就是本机IP,这里是139.129.192.245。</p>    <p>下载busybox镜像并重新tag:</p>    <pre>  <code class="language-haskell">$ docker pull busybox  $ docker tag busybox 139.129.192.245:5000/busybox</code></pre>    <p>push到是私有仓库:</p>    <pre>  <code class="language-haskell">$ docker push 139.129.192.245:5000/busybox  The push refers to a repository [139.129.192.245:5000/busybox]  Get https://139.129.192.245:5000/v1/_ping: http: server gave HTTP response to HTTPS client</code></pre>    <p>发现出错了。从错误信息来看,client与Registry交互,默认将采用https访问,但我们在install Registry时并未配置指定任何tls相关的key和crt文件,https访问定然失败。要想弄清这个问题,只能查看 Registry Manual 。</p>    <p>解决方案:修改Registry server上的Docker daemon的配置, ExecStart 参数后面增加 –insecure-registry :</p>    <pre>  <code class="language-haskell">ExecStart=/usr/bin/dockerd --registry-mirror=http://019a7061.m.daocloud.io  --insecure-registry 139.129.192.245:5000</code></pre>    <p>重启:</p>    <pre>  <code class="language-haskell">$ systemctl restart docker.service</code></pre>    <p>由于容器加了启动参数 --restart=always ,docker Engine重启后容器会自动重启。我们再次push镜像到私有仓库:</p>    <pre>  <code class="language-haskell">$ docker push 139.129.192.245:5000/busybox  The push refers to a repository [139.129.192.245:5000/busybox]  e88b3f82283b: Pushed   latest: digest: sha256:29f5d56d12684887bdfa50dcd29fc31eea4aaf4ad3bec43daf19026a7ce69912 size: 527</code></pre>    <p>成功了。</p>    <h3><strong>4、查看仓库信息</strong></h3>    <pre>  <code class="language-haskell">$ curl  http://139.129.192.245:5000/v2/_catalog  {"repositories":["busybox"]}    $ curl  http://139.129.192.245:5000/v2/busybox/tags/list  {"name":"busybox","tags":["latest"]}</code></pre>    <p>参考:</p>    <p>1、部署私有Docker Registry | Tony Bai</p>    <p> </p>    <p> </p>    <p>来自:http://www.cnblogs.com/52fhy/p/5998747.html</p>    <p> </p>