docker的私有仓库的搭建

Posted kaishirenshi

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了docker的私有仓库的搭建相关的知识,希望对你有一定的参考价值。

author: headsen chen 

date:2018-06-30  23:14:16

服务端(私有仓库:centos7_64位),使用端:centos6_64位

1、仓库的搭建:

安装docker:

yum -y install epel-release
yum -y install docker-io
systemctl start docker

将本地的仓库换成阿里云的镜像仓库

 

vim /etc/docker/daemon.json  # 内容如下:

{
  "registry-mirrors": ["https://cvv5tle1.mirror.aliyuncs.com"]  # 这里的镜像源是我专属的, 其他人用可能起不到加速效果
}
 systemctl daemon-reload
 systemctl restart docker

在本地注册阿里云的镜像:
docker login --username=woccb registry.cn-hangzhou.aliyuncs.com/woccb2/chen
输入设置的密码

 

运行一个生成本地仓库的脚本:

sh registry-install.sh

[[email protected] ~]# cat registry-install.sh 
#!/bin/bash
# Description: create a private registry v2.2
# Version: 0.2
# Author: headsen chen


set -o xtrace if [[ $UID -ne 0 ]]; then echo "Not root user. Please run as root." exit 0 fi # Install Docker if not docker -v if [[ $? -ne 0 ]]; then echo "Please install Docker first." exit 0 fi REGISTRY_VERSION=2.2 # Download registry image v2.2 docker pull registry:${REGISTRY_VERSION}
# Start registry container mkdir
/opt/registry docker run -d -p 5000:5000 --restart=always -v /opt/registry:/var/lib/registry --name hummer_registry registry:${REGISTRY_VERSION}

检测生成的docker仓库:

[[email protected] ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
eaa972942548        registry:2.2        "/bin/registry /et..."   35 minutes ago      Up 35 minutes       0.0.0.0:5000->5000/tcp   hummer_registry
[[email protected] ~]# 

查询开放的端口:

[[email protected] ~]# lsof -i:5000
COMMAND     PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
docker-pr 18119 root    4u  IPv6  50113      0t0  TCP *:commplex-main (LISTEN)

2、客户端配置:

安装

yum -y install epel-release
yum -y install device-mapper-event-libs
yum -y install docker-io

修改配置文件(不修改无法和本地仓库进行认证连接)

vim /etc/sysconfig/docker   # 加上黄色标注的部分就可以了

[[email protected] ~]# cat /etc/sysconfig/docker
# /etc/sysconfig/docker
#
# Other arguments to pass to the docker daemon process
# These will be parsed by the sysv initscript and appended
# to the arguments list passed to docker -d

other_args="--insecure-registry 192.168.159.131:5000"
DOCKER_CERT_PATH=/etc/docker

# Resolves: rhbz#1176302 (docker issue #407)
DOCKER_NOWARN_KERNEL_VERSION=1

 service docker restart

测试:下载一个镜像并上传到本地仓库

docker pull webdevops/nginx
docker images
docker tag webdevops/nginx 192.168.159.131:5000/nginx-chen # 注意这个固定的格式,否则报错
docker push 192.168.159.131:5000/nginx-chen  #出现以下提示表示push成功
技术分享图片
[[email protected] ~]# docker push 192.168.159.131:5000/nginx-chen 
The push refers to a repository [192.168.159.131:5000/nginx-chen] (len: 1)
ca89ae17bc84: Image already exists 
2eed794b7b9a: Image successfully pushed 
15a4031b10d3: Image successfully pushed 
15a4031b10d3: Buffering to Disk 
6c4863f14961: Image already exists 
aa02f81f314b: Image already exists 
0893fa3a44c9: Image successfully pushed 
6565352c3a2b: Image successfully pushed 
6565352c3a2b: Buffering to Disk 
e86584bf870d: Image successfully pushed 
928d4898ab17: Image successfully pushed 
928d4898ab17: Buffering to Disk 
073806b60691: Image already exists 
7eb5c12881e1: Image already exists 
63474e4f2842: Image successfully pushed 
f7fdafe228d3: Image successfully pushed 
8475d7efa2f0: Image successfully pushed 
565220263a7c: Image successfully pushed 
7d614f18edc3: Image successfully pushed 
Digest: sha256:417cfafb30d330f5de3c9cef12ee935a321d16593bdd903de3d1017ad3eaa3f3
[[email protected] ~]#
View Code

删除下载的镜像,并从本地的仓库进行下载,看速度是否提高:

docker rmi webdevops/nginx
docker rmi 192.168.159.131:5000/nginx-chen
docker images
docker pull 192.168.159.131:5000/nginx-chen # 此时从本地的仓库进行下载,发现是极速的秒传

查询私有仓库中有哪些镜像: 

docker search registry_ip:5000/

 







以上是关于docker的私有仓库的搭建的主要内容,如果未能解决你的问题,请参考以下文章

Docker私有仓库搭建与界面化管理

Docker私有仓库的搭建与使用

docker 私有仓库搭建以及用户认证

搭建docker私有镜像仓库

11-Docker-搭建私有仓库

docker搭建私有仓库