设为首页 收藏本站
查看: 1686|回复: 0

[经验分享] 搭建 Docker-Registry 私有仓库

[复制链接]

尚未签到

发表于 2015-4-17 10:29:34 | 显示全部楼层 |阅读模式
  官方已经提供了很多版本的 Linux 镜像,直接从官方仓库(Public Repositories)下载就可以了。如果考虑到安全性和速度,我们可能会想在自己局域网里架设一个私有仓库(Private Repositories)来放我们自己的镜像,Docker-Registry 正是我们需要的工具。

本次搭建

docker-registry server (dev) (v0.9.0)

添加docker用户和目录
  为了安全起见,我们可以添加一个用户docker,使用这个非root用户来允许docker registry程序,同时指定好docker镜像的存储位置,本处指定为/home/docker_registry目录



useradd docker
mkdir -p /home/docker_registry
chown -R docker.docker /home/docker_registry/

  从github克隆最新版本registry, 进入这个目录下的config子目录,从模板复制一个配置文件出来:



git clone https://github.com/docker/docker-registry.git
cd docker-registry/config
cp config_sample.yml config.yml
  此时可以修改这个config.yml配置文件,需要注意修改以下的两个地方:



#配置sqlite数据库位置
sqlalchemy_index_database: _env:SQLALCHEMY_INDEX_DATABASE:sqlite:////home/docker_registry/docker-registry.db
#配置本地存储位置
local: &local
storage: local
storage_path: _env:STORAGE_PATH:/home/docker_registry
  安装一些必要软件包和一些 Docker-Registry 需要用到的 Python 工具和库:



apt-get update
apt-get install build-essential python-dev liblzma-dev libevent-dev python-pip libssl-dev
  使用apt-get安装软件包时经常会提示让你插入netinst的光盘:



Media change: please insert the disc labeled
  当没有时就无法进行安装了, 这时可以打开文件/etc/apt/sources.list文件,注释掉cdrom那一行,
  然后再执行apt-get update更新下deb仓库,
  这样以后再使用apt-get安装时就不会再搜寻cdrom了
  修改HOSTS文件加上域名



vim /etc/hosts
127.0.0.1 docker.registry.com
  安装Nginx



apt-get install nginx
#配置Nginx config
vim /etc/nginx/nginx.conf


user www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
##
# nginx-naxsi config
##
# Uncomment it if you installed nginx-naxsi
##
#include /etc/nginx/naxsi_core.rules;
##
# nginx-passenger config
##
# Uncomment it if you installed nginx-passenger
##
#passenger_root /usr;
#passenger_ruby /usr/bin/ruby;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
upstream docker-registry {
server localhost:5000;
}
server {
listen 80;
server_name docker.registry.com;
proxy_set_header Host       $http_host;   # required for docker client's sake
proxy_set_header X-Real-IP  $remote_addr; # pass on real client's IP
client_max_body_size 0; # disable any limits to avoid HTTP 413 for large image uploads
# required to avoid HTTP 411: see Issue #1486 (https://github.com/dotcloud/docker/issues/1486)
chunked_transfer_encoding on;
#     
location / {
proxy_pass http://docker-registry;
}
}
}
  启动Nginx



service nginx start
  访问浏览器测试



http://192.168.124.130/
DSC0000.png
  
  安装python依赖



cd /opt/docker-registry
pip install .
  若出现:Cannot connect to proxy. Socket error: [Errno -2] Name or service not known.
  手动安装依赖包 加代理参数



pip install -i http://pypi.v2ex.com/simple .
#注销下面的 pip install . 安装全部
--pip install -i http://pypi.v2ex.com/simple gunicorn
  建立软连接



ln -s /usr/local/bin/gunicorn /usr/bin/gunicorn
  nginx启动之后,使用docker用户执行以下的命令可以测试启动:



gunicorn --access-logfile - --error-logfile - -k gevent -b 0.0.0.0:5000 -w 8 --max-requests 100 docker_registry.wsgi:application
  访问浏览器



http://docker.registry.com
DSC0001.png
  如果看到以下的输出,则表明docker registry安装成功
  给目录下数据库赋权限,不然上传文件时会不能写数据库



chmod 777 /home/docker_registry/repositories/docker-registry.db
  

使用supervisord来进行进程的监控



apt-get install supervisor
  配置supervisor [docker-registry]



vim /etc/supervisor/conf.d/docker-registry.conf


[program:docker-registry]
directory=/opt/docker-registry
#使用docker用户
user=docker
command=/usr/local/bin/gunicorn --access-logfile - --error-logfile - -k gevent -b 0.0.0.0:5000 -w 8 --max-requests 100 --graceful-timeout 3600 -t 3600 docker_registry.wsgi:application
redirect_stderr=true
stderr_logfile=none
stdout_logfile=/var/log/supervisor/docker-registry.log
autostart=true
autorestart=true
  重新加载 supervisor 配置:



supervisorctl
supervisor> reread
docker-registry: available
supervisor> update
docker-registry: added process group
supervisor> status
docker-registry   RUNNING    pid 4371, uptime 0:00:01

  查看端口占用



netstat -apn | grep 5000
  启动重启



service supervisor start
#/etc/init.d/supervisord {start|stop|restart|force-reload|status|force-stop}
  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-58071-1-1.html 上篇帖子: docker summary 下篇帖子: Docker学习总结之docker介绍
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表