docker建立本地私有仓库报错解决

其实建立docker仓库有三种方法。

1.直接pull下来,docker官网提供的registry镜像。(docker run -d -p 5000:5000 registry)

2.使用git上面的源码进行创建。或者本地使用pip安装。

3.同样基于git的源码,我们build成image,然后执行这个image。

好明显第一第三种是拼网速的活,不适合我,因此本文选择第二种。假如网速这么好,为毛还要在本地自建仓库?直接在docker hub上刷刷刷搞了。- -!

环境:ubuntu14.04

本地建立docker-registry

apt-get install -y build-essential python-dev libevent-dev python-pip liblzma-dev

pip install docker-registry

报错:
111

初步判定是swig问题,swig没安装

安装swig

apt-get install swig

33

报错依旧,这次提示是m2crypto没找到,然后继续安装。


222

安装完后之前的报错没了,但是出现了新的报错。
如下:
SWIG/_evp.i:12: Error: Unable to find 'openssl/opensslconf.h'
SWIG/_ec.i:7: Error: Unable to find 'openssl/opensslconf.h'

软件包没问题了,文件路径问题,后经检查没有找到openssl路径,然后继续安装
44
安装完后,再次执行
pip install docker-registry

这次已经成功安装了。

root@kingsoft:/usr/include# pip list|grep docker-registry
docker-registry (0.9.1)
docker-registry-core (2.0.3)

继续执行:
gunicorn --access-logfile - --error-logfile - -k gevent -b 0.0.0.0:5000 -w 1 docker_registry.wsgi:application

报错:
FileNotFoundError: Heads-up! File is missing: /usr/local/lib/python2.7/dist-packages/docker_registry/lib/../../config/config.yml
[2016-01-07 01:51:18 +0000] [9313] [INFO] Worker exiting (pid: 9313)
[2016-01-07 01:51:18 +0000] [9308] [INFO] Shutting down: Master
[2016-01-07 01:51:18 +0000] [9308] [INFO] Reason: Worker failed to boot.

由于配置文件不在正确的位置报错,registry在同样的路径上包含一个示例配置文件,该文件名为config_sample.yml,因此,我们可以通过上述给出的路径名来定位示例配置文件。从错误消息中复制路径信息解决。

先按照报错提示进到指定目录,果然没有config.yml文件。我们需要将
config_sample.ml的内容写到config.ml中去。
root@kingsoft:/usr/include# cd /usr/local/lib/python2.7/dist-packages/docker_registry/lib/../../config/
root@kingsoft:/usr/local/lib/python2.7/dist-packages/config# ll
total 24
drwxr-sr-x 2 root staff 4096 Jan 7 00:50 ./
drwxrwsr-x 41 root staff 4096 Jan 7 01:32 ../
-rw-r--r-- 1 root staff 73 Jan 7 00:49 boto.cfg
-rw-r--r-- 1 root staff 351 Jan 7 00:49 config_mirror.yml
-rw-r--r-- 1 root staff 7631 Jan 7 00:49 config_sample.yml

执行cp config_sample.yml config.ml操作。

之后继续运行

root@kingsoft:/usr/local/lib/python2.7/dist-packages/config# gunicorn --access-logfile - --error-logfile - -k gevent -b 0.0.0.0:5000 -w 4 --max-requests 100 docker_registry.wsgi:application
[2016-01-07 02:05:34 +0000] [9375] [INFO] Starting gunicorn 19.1.1
[2016-01-07 02:05:34 +0000] [9375] [INFO] Listening at: http://0.0.0.0:5000 (9375)
[2016-01-07 02:05:34 +0000] [9375] [INFO] Using worker: gevent
[2016-01-07 02:05:34 +0000] [9380] [INFO] Booting worker with pid: 9380
[2016-01-07 02:05:34 +0000] [9381] [INFO] Booting worker with pid: 9381
[2016-01-07 02:05:34 +0000] [9382] [INFO] Booting worker with pid: 9382
[2016-01-07 02:05:34 +0000] [9383] [INFO] Booting worker with pid: 9383
07/Jan/2016:02:05:34 +0000 WARNING: Cache storage disabled!
07/Jan/2016:02:05:34 +0000 WARNING: LRU cache disabled!
07/Jan/2016:02:05:34 +0000 DEBUG: Will return docker-registry.drivers.file.Storage
07/Jan/2016:02:05:34 +0000 WARNING: Cache storage disabled!
07/Jan/2016:02:05:34 +0000 WARNING: LRU cache disabled!
07/Jan/2016:02:05:34 +0000 DEBUG: Will return docker-registry.drivers.file.Storage
07/Jan/2016:02:05:34 +0000 WARNING: Cache storage disabled!
07/Jan/2016:02:05:34 +0000 WARNING: LRU cache disabled!
07/Jan/2016:02:05:34 +0000 DEBUG: Will return docker-registry.drivers.file.Storage
07/Jan/2016:02:05:34 +0000 WARNING: Cache storage disabled!
07/Jan/2016:02:05:34 +0000 WARNING: LRU cache disabled!
07/Jan/2016:02:05:34 +0000 DEBUG: Will return docker-registry.drivers.file.Storage

没有报错了,错看一下端口发现5000已经起来了

root@kingsoft:~# 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 831/sshd 
tcp 0 0 0.0.0.0:5000 0.0.0.0:* LISTEN 9346/python 
tcp6 0 0 :::22 :::* LISTEN 831/sshd
docker registry已经跑起来了。

备注一下重点:
无法push成功到仓库

root@kingsoft:~# docker push 10.20.122.73:5000/test

FATA[0000] Error response from daemon: v1 ping attempt failed with error: Get https://10.20.122.73:5000/v1/_ping: dial tcp 10.20.122.73:5000: connection refused. If this private registry supports only HTTP or HTTPS with an unknown CA certificate, please add `--insecure-registry 10.20.122.73:5000` to the daemon's arguments. In the case of HTTPS, if you have access to the registry's CA certificate, no need for the flag; simply place the CA certificate at /etc/docker/certs.d/10.20.122.73:5000/ca.crt

解决方法:
1.private registry上使用SSL配合nginx使用。
2.强制普通方式。
因为是测试环境,不考虑安全问题,我用第二种方法。修改docker配置文件
213
 
然后重启docker服务。

root@kingsoft:~# ps aux |grep docker
root 9629 0.5 0.2 440324 16896 ? Ssl 02:50 0:00 /usr/bin/docker -d --insecure-registry myregistry:5000

root@kingsoft:~# docker push 10.20.122.73:5000/test
The push refers to a repository [10.20.122.73:5000/test] (len: 1)
Sending image list
Pushing repository 10.20.122.73:5000/test (1 tags)
3f12c794407e: Image successfully pushed 
975b84d108f1: Image successfully pushed 
Pushing tag for rev [975b84d108f1] on {http://10.20.122.73:5000/v1/repositories/test/tags/latest}

push成功。

发表评论

电子邮件地址不会被公开。 必填项已用*标注

您可以使用这些HTML标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>