Build Docker Registry Private warehouse in Ubuntu

Source: Internet
Author: User
Tags docker hub docker run docker registry

Why to build a Docker private warehouse

There are several reasons:

    1. Project needs and do not want to put the project on the Docker hub.
    2. Environmental requirements, considering the network, efficiency issues, we hope to establish a private server for self-owned warehouses, improve convenience and access speed.
    3. Can do more personalized configuration.
What to use to build a Docker private warehouse

Docker officially provides a registry image that can be used to build a private repository.

The environment of this building

Here, let's explain the experimental environment of this article:

    1. Docker Warehouse Server: Ubuntu 14.04 IP Address: 192.168.188.112
    2. Docker client machine: CentOS 7 IP Address: 192.168.188.107
Build process Objectives

On the Ubuntu 14 server, install the latest version of Docker-ce, get the registry image at the Docker hub, and start the warehouse container. On the Docker client machine, you can get the image file from the server's warehouse.

Server installs the latest version of Docker-ce
 curl  -sSL   https://get.docker.com/   |   sh

Note: The installation process depends on the network conditions, may require a period of time, need to wait patiently

Installing Accelerators

Because at home, visiting foreign sites may be slower, so it's best to add accelerators for Ubuntu.

For the Ubuntu 14 system environment, modify the file/etc/default/docker:

DOCKER_OPTS="--registry-mirror=https://registry.docker-cn.com"
Get the official registry image from the Docker hub and launch the registry container
1.   获取 registry 镜像:      docker   pull   registry   # 默认就是最新的 latest 版本2.  用registry 镜像启动一个仓库容器:     docker run -d   --name=my-docker-registry-2  --restart=always -p 5000:5000   -v  /opt/data/registry:/tmp/registry    registry说明:启动一个名字为 my-docker-registry-2 的容器,端口映射到宿主机的5000,挂载宿主机目录 /opt/data/registry 到容器的 /tmp/registry ,用于存储 push 进去的镜像文件。   
Local Test warehouse on host

1. Get an Ubuntu 16.04 image from the Docker hub

docker  pull   ubuntu:16.04  

2. Re-tag the image you acquired above:

docker  tag    ubuntu:16.04    192.168.188.112:5000/my-ubuntu

3. Push the newly tagged image to the local repository, and the Docker command will go from the ". And: "The format identifies the repository that is the local path:

docker   push   192.168.188.112:5000/my-ubuntu

4. Delete the image downloaded from the Docker hub:

docker  rmi    ubuntu:16.04    192.168.188.112:5000/my-ubuntu说明:   删除了本地的两个镜像文件docker    images   说明:查看本地的镜像文件,确认上一步已经删除成功。

5. See if the image in the repository has been uploaded successfully:

[email protected]:~$   curl localhost:5000/v2/_catalog{"repositories":["my-ubuntu"]}说明:  这样,已经就是查询到push 镜像成功了。

6. Pull the image from the local repository:

docker   pull  192.168.188.112:5000/my-ubuntu说明: docker 命令通过“ .   : ”识别是本地仓库

7. Results:

[email protected]:~$ docker images REPOSITORY                            TAG                 IMAGE ID            CREATED             SIZE127.0.0.1:5000/my-ubuntu       latest              9adf4ebd74b9        3 weeks ago         285MB192.168.188.112:5000/my-ubuntu   latest              9adf4ebd74b9        3 weeks ago         285MBregistry        说明: 可以看到用 127.0.0.1或者192.168.188.112两个地址都能获取成功
Getting mirrors from other machines

We have built a private warehouse, and if we can only use it on a single host, it doesn't make much sense. However, the official registry private warehouse does not support direct access to the warehouse server by other clients. You need to do some more configuration changes.

Using methods that modify the--insecure-registry parameter

The simplest way to modify the--insecure-registry parameter is to do so. If you need more security, you need to configure SSL access, which is left for later research.

Warehouse Server Modifications
ubuntu 默认文件是sudo  vim    /etc/default/docker 修改:DOCKER_OPTS="--registry-mirror=https://registry.docker-cn.com --insecure-registry=192.168.188.112:5000"
Restart the Docker process after you modify the configuration

In order to restart the Docker daemon, it will not cause all containers to be forced to shut down, some configuration files need to be modified, please refer to this blog post: "How to ensure that the Docker daemon restarts without causing the container to shut down"

CentOS Client Configuration

The system that the client uses is CentOS 7 and installs the DOCKER-CE version on CentOS 7, please refer to this blog post: "Centos7 installation Docker-ce new Edition".

1. After installing the DOCKER-CE version as described above, modify the configuration file:

vim    /lib/systemd/system/docker.service 添加: ExecStart=/usr/bin/dockerd  --insecure-registry 192.168.188.112:5000

The Docker daemon daemon restarts, by default, does not cause the container to be forced to shut down, so after modifying the configuration file, you can safely restart the background process:

systemctl   restart   docker

2. Verification

[[email protected]_7 ~]# curl -L http://192.168.188.112:5000/v2/_catalog{"repositories":["my-ubuntu-sshd"]}

3. Download the image from the private repository

docker   pull    192.168.188.112:5000/my-ubuntu

4. Download the image file successfully

[[email protected]_7 ~]# docker images REPOSITORY                            TAG                 IMAGE ID            CREATED             SIZEubuntu                                14.04               dc4491992653        2 weeks ago         222MB192.168.188.112:5000/my-ubuntu        latest              9adf4ebd74b9        3 weeks ago         285MB
Summarize

Docker's official registry repository, by default, does not support pulling the server repository's image files from other clients, but the easy way is to open the--insecure-registry option.

Build Docker Registry Private warehouse in Ubuntu

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.