Docker-构建私有仓库Registry

本文详细介绍如何部署和使用私有Docker Registry,包括配置、异常处理及跨机器拉取镜像的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Registry的部署

 

 

获取registry镜像

[root@controller~]# docker pull registry

[root@controller~]# docker images

REPOSITORY             TAG                 IMAGE ID            CREATED             VIRTUAL SIZE

centos7-base           latest              d0ba4418aa31        14 hours ago        590.3 MB

registry               latest              dd399a13752f        8 days ago          33.18 MB

[root@controller ~]#

[root@controller ~]# netstat -ntlp

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name  

tcp       0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      1334/sshd          

tcp       0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      1412/master        

tcp       0      0 :::22                       :::*                        LISTEN      1334/sshd          

tcp       0      0 :::91                       :::*                        LISTEN      12173/docker-proxy 

tcp       0      0 :::92                       :::*                        LISTEN      12835/docker-proxy 

tcp       0      0 :::32770                    :::*                        LISTEN      11831/docker-proxy 

[root@controller ~]#

 

 

启动一容器作为私有仓库

[root@controller~]# docker run -d -p 5001:5000 registry

f2b73eee61e1fb7dc26b8c55445d5f024406e859f19c31b187dc1b2d4631a509

[root@controller ~]#

[root@controller ~]# docker ps -l

CONTAINER ID       IMAGE               COMMAND                CREATED             STATUS              PORTS                    NAMES

f2b73eee61e1       registry            "/entrypoint.sh /etc   6 seconds ago       Up 5 seconds        0.0.0.0:5001->5000/tcp   happy_bartik       

[root@controller ~]#

 

 

 

制作镜像作为上传私有仓库测试

[root@controller~]# docker tag centos7-base 192.168.2.20:5001/test/centos7base:v1

[root@controller ~]# docker images

REPOSITORY                           TAG                 IMAGE ID            CREATED             VIRTUAL SIZE

192.168.2.20:5001/test/centos7base   v1                  d0ba4418aa31        14 hours ago        590.3 MB

centos7-base                         latest              d0ba4418aa31        14 hours ago        590.3 MB

registry                             latest              dd399a13752f        8 days ago          33.18 MB

lemonbar/centos6-ssh                 latest              b78c71c001db        2 years ago         296.9 MB

[root@controller ~]#

 

 

向私有仓库上传刚刚制作的镜像

[root@controller~]# docker push 192.168.2.20:5001/test/centos7base:v1

Errorresponse from daemon: invalid registry endpoint https://192.168.2.20:5001/v0/:unable to ping registry endpoint https://192.168.2.20:5001/v0/

v2 ping attempt failed with error: Gethttps://192.168.2.20:5001/v2/: tls: oversized record received with length 20527

 v1 pingattempt failed with error: Get https://192.168.2.20:5001/v1/_ping: tls:oversized record received with length 20527. If this private registry supportsonly HTTP or HTTPS with an unknown CA certificate, please add `--insecure-registry192.168.2.20:5001` to the daemon's arguments. In the case of HTTPS, ifyou have access to the registry's CA certificate, no need for the flag; simplyplace the CA certificate at /etc/docker/certs.d/192.168.2.20:5001/ca.crt

[root@controller ~]#

 

 

异常处理

[root@controller~]# vim /etc/sysconfig/docker

[root@controller~]# cat /etc/sysconfig/docker

# /etc/sysconfig/docker

#

# Other arguments to pass to the docker daemonprocess

# These will be parsed by the sysv initscript andappended

# to the arguments list passed to docker -d

 

other_args="--insecure-registry192.168.2.20:5001"

DOCKER_CERT_PATH=/etc/docker

 

# Resolves: rhbz#1176302 (docker issue #407)

DOCKER_NOWARN_KERNEL_VERSION=1

 

# Location used for temporary files, such as thosecreated by

# # docker load and build operations. Default is/var/lib/docker/tmp

# # Can be overriden by setting the followingenvironment variable.

# # DOCKER_TMPDIR=/var/tmp

[root@controller ~]#

[root@controller~]# /etc/init.d/docker restart

[root@controller ~]# docker ps -l

CONTAINER ID       IMAGE               COMMAND                CREATED             STATUS                      PORTS               NAMES

f2b73eee61e1       registry            "/entrypoint.sh /etc   11 minutes ago      Exited (2) 43 seconds ago                       happy_bartik       

[root@controller ~]#

[root@controller~]# docker start f2b73eee61e1

[root@controller ~]# docker ps -l

CONTAINER ID       IMAGE               COMMAND                CREATED             STATUS              PORTS                    NAMES

f2b73eee61e1       registry           "/entrypoint.sh /etc   11minutes ago      Up 9 seconds        0.0.0.0:5001->5000/tcp   happy_bartik       

[root@controller ~]#

说明:

         1)编辑/etc/sysconfig/docker文件;

         2)加上参数other_args="--insecure-registry 192.168.2.20:5001",即指定私有仓库地址;

         3)重启docker服务;

         4)启动私有仓库容器;

 

 

运行docker ps看一下容器情况

[root@controller~]# docker ps

CONTAINER ID       IMAGE               COMMAND                CREATED             STATUS              PORTS                    NAMES

f2b73eee61e1       registry           "/entrypoint.sh /etc   11minutes ago     Up 9 seconds       0.0.0.0:5001->5000/tcp   happy_bartik       

[root@controller ~]#

 

 

 

输入地址测试

http://192.168.2.20:5001/v2/

说明:

         1)打开浏览器,输入上面地址;

         2)若返回{},则说明registry运行正常;

 

 

 

继续上传刚刚制作的镜像

[root@controller~]# docker push 192.168.2.20:5001/test/centos7base:v1

The push refers to a repository[192.168.2.20:5001/test/centos7base] (len: 1)

d0ba4418aa31: Image already exists

f7918e717f8a: Image successfully pushed

a4708aa4c5d8: Image successfully pushed

7cd5636c6c7b: Image successfully pushed

b334027ca058: Image successfully pushed

b96ef7348a7f: Image successfully pushed

9d67542497a1: Image successfully pushed

31e0308b83e2: Image successfully pushed

e68d43528dbf: Image successfully pushed

b684c29bd301: Image successfully pushed

439821e94d52: Image successfully pushed

7938ba639df4: Image successfully pushed

ca668e903aa7: Image successfully pushed

ca668e903aa7: Buffering to Disk

72a210db1424: Image already exists

f19a7b85bfcf: Image successfully pushed

Digest:sha256:38a9c650070e940eb2af3af8a3d0a36fe6457a65dc97a0ce2623f0f5aec8117c

[root@controller ~]#

 

 

 

在另外一台机器上下载私有仓库中的镜像

 

 

概述

       这一台机器是Ubuntu,上面也装了docker;

       在这台机器上下载私有仓库中的镜像;

 

 

修改docker配置文件,指定私有仓库地址

root@ubuntu02:~# cd /etc/default/

root@ubuntu02:/etc/default# vim docker

root@ubuntu02:/etc/default# cat /etc/default/docker

......

DOCKER_OPTS="--insecure-registry192.168.2.20:5001"

......

root@ubuntu02:~#

 

 

重启docker服务

root@ubuntu02:/etc/default#service docker restart

docker stop/waiting

docker start/running, process 2306

root@ubuntu02:/etc/default# docker images     

REPOSITORY             TAG                 IMAGE ID            CREATED             SIZE

cct                   latest              9ca8d599337a        5 days ago          239MB

weaveworks/weaveexec   latest              f8f2bacce064        8 days ago          108MB

weaveworks/weave       latest              97d546443db4        8 days ago          58.3MB

weaveworks/weavedb     latest              3f610642de09        7 weeks ago         252B

root@ubuntu02:/etc/default#

 

 

 

拉取刚刚在centos中上传的镜像

root@ubuntu02:/etc/default#docker pull 192.168.2.20:5001/test/centos7base:v1

root@ubuntu02:/etc/default# docker images

REPOSITORY                           TAG                 IMAGE ID            CREATED             SIZE

192.168.2.20:5001/test/centos7base   v1                  7271c87c22bb        19 hours ago        590MB

cct                                  latest              9ca8d599337a        5 days ago          239MB

weaveworks/weaveexec                 latest              f8f2bacce064        8 days ago          108MB

weaveworks/weave                     latest              97d546443db4        8 days ago          58.3MB

weaveworks/weavedb                   latest              3f610642de09        7 weeks ago         252B

root@ubuntu02:/etc/default#

 

 

从私有仓库下载的镜像启动容器

root@ubuntu02:/etc/default#docker run -it 192.168.2.20:5001/test/centos7base:v1

[root@051bf4bf1ccb /]# ifconfig

eth0:flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet172.17.0.2  netmask 255.255.0.0  broadcast 0.0.0.0

        ether02:42:ac:11:00:02  txqueuelen 0  (Ethernet)

        RXpackets 38  bytes 6238 (6.0 KiB)

        RXerrors 0  dropped 0  overruns 0 frame 0

        TXpackets 0  bytes 0 (0.0 B)

        TXerrors 0  dropped 0 overruns 0  carrier 0 collisions 0

 

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536

        inet127.0.0.1  netmask 255.0.0.0

       loop  txqueuelen 0  (Local Loopback)

        RXpackets 0  bytes 0 (0.0 B)

        RXerrors 0  dropped 0  overruns 0 frame 0

        TXpackets 0  bytes 0 (0.0 B)

        TXerrors 0  dropped 0 overruns 0  carrier 0 collisions 0

 

[root@051bf4bf1ccb /]# ps -ef|grep httpd

root        17      1  0 17:26 pts/0    00:00:00 grep --color=auto httpd

[root@051bf4bf1ccb /]# /usr/sbin/httpd

[root@051bf4bf1ccb /]# ps -ef|grep httpd

root        20      1  0 17:27 ?        00:00:00 /usr/sbin/httpd

apache      21     20  0 17:27 ?        00:00:00 /usr/sbin/httpd

apache      22     20  0 17:27 ?        00:00:00 /usr/sbin/httpd

apache      23     20  0 17:27 ?        00:00:00 /usr/sbin/httpd

apache      24     20  0 17:27 ?        00:00:00 /usr/sbin/httpd

apache      25     20  0 17:27 ?        00:00:00 /usr/sbin/httpd

root        27      1  0 17:27 pts/0    00:00:00 grep --color=auto httpd

[root@051bf4bf1ccb /]#

[root@051bf4bf1ccb /]# curl -I 127.0.0.1/index.html

HTTP/1.1 404 Not Found

Date: Fri, 07 Jul 2017 17:27:55 GMT

Server: Apache/2.4.6 (CentOS)

Content-Type: text/html; charset=iso-8859-1

 

[root@051bf4bf1ccb /]#

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值