搭建docker私有仓库

安装Dockerlinux

Docker的安装请参考官网(http://www.docker.com),很是详细的介绍了各个操做系统的部署过程。docker

对于CentOS 7.x操做系统的在线安装Docker,请参考以下:https://docs.docker.com/engine/installation/linux/centoscentos

若是使用离线RPM包安装Docker请参考另外一个篇博客:安全

http://blog.csdn.net/jiangshouzhuang/article/details/52822125操作系统

 

搭建Docker私有仓库.net

Docker官方提供了一个公有的registry叫作Docker Hub。可是企业内部可能有些镜像仍是不方便放到公网上去,因此docker也提供了registry镜像来让须要的人本身搭建私有仓库。rest

咱们这里以Docker官方提供的镜像Registry建立本地私有仓库,建立方式和启动一个普通镜像的方式是同样。code

拉取registry镜像blog

registry须要从Docker Hub先拉取下来:ip

docker pullregistry:2

拉取完成后,能够执行dockerimages进行查看。

 

启动registry

docker run -d -p 5000:5000 --restart=always \

        --nameregistry \

        -v /config.yml:/etc/docker/registry/config.yml \`pwd`
        -v /var/lib/registry:/var/lib/registry \

       registry:2

 

 

registry v2 取消安全认证

registry启动以后,V2版本的默认须要安全连接,私有仓库能够移除。

修改docker服务启动脚本,在/usr/lib/systemd/system/docker.service脚本中添加EnvironmentFile位置,而且增长Docker启动参数$INSECURE_REGISTRY,具体内容以下:

[Unit]

Description=Docker Application Container Engine

Documentation=https://docs.docker.com

After=network.target

 

[Service]

Type=notify

EnvironmentFile=/etc/sysconfig/docker

ExecStart=/usr/bin/dockerd $INSECURE_REGISTRY--cluster-store=etcd://192.168.1.23:2379

ExecReload=/bin/kill -s HUP $MAINPID

MountFlags=slave

LimitNOFILE=1048576

LimitNPROC=1048576

LimitCORE=infinity

TimeoutStartSec=0

# set delegate yes so that systemd does not reset thecgroups of docker containers

Delegate=yes

# kill only the docker process, not all processes in thecgroup

KillMode=process

 

[Install]

WantedBy=multi-user.target

而后新建/etc/sysconfig/docker文件,在里边添加一行

INSECURE_REGISTRY='--insecure-registry 192.168.1.23:5000'

 

最后重启Docker

systemctl daemon-reload

systemctl restart docker

 

客户端也一样须要调整,不然将没法从私有仓库pull镜像

cat /etc/sysconfig/docker

INSECURE_REGISTRY='--insecure-registry 192.168.1.23:5000'

ADD_REGISTRY='--add-registry 192.168.1.23:5000'

 

上传镜像到私有镜像仓库

给镜像打个标签:

docker tag centos:7.2 192.168.1.23:5000/centos:7.2

 

上传镜像到私有镜像仓库:

docker push 192.168.1.23:5000/centos:7.2

 

其余Docker节点从私有镜像仓库中拉取镜像

从私有镜像仓库中拉去以前咱们上传的镜像:

[root@testbig25 ~]# docker pull 192.168.1.23:5000/centos:7.2

7.2: Pulling from centos

a3ed95caeb02: Pull complete

bc4d85eaf590: Pull complete

Digest:sha256:05c5e4ffbd3e4e54a685915394858e1dacc38873f02920b57b66551a1626dbd3

Status: Downloaded newer image for 192.168.1.23:5000/centos:7.2

 

拉取成功后,能够执行docker images进行查看。