1.安装docker-registry


#直接从官网pull镜像registry,简单粗暴。国内可能速度较慢,考虑挂VPN

docker pull registry


按照上一篇中的方式修改--insecure-registry设置及config.yml文件


2.运行docker-registry


#后台启动registry,其中/home/alvin/registry为我本地仓库的存储路径

docker run -d -v /home/alvin/registry:/tmp/registry -p 5000:5000 -e  DOCKER_REGISTRY_CONFIG=/tmp/registry/config.yml registry


问题记录:每次重新运行时镜像丢失

解决方法:修改仓库路径到本地

docker run -d -e SETTINGS_FLAVOR=dev -e STORAGE_PATH=/tmp/registry -v /home/alvin/registry:/tmp/registry -p 5000:5000 registry


至此已经可以正常的push/pull操作了


3.nginx代理认证


#安装nginx

sudo apt-get install -y nginx apache2-utils

#创建用户名及密码

sudo htpasswd -c /etc/nginx/docker-registry.htpasswd [USERNAME]


#配置nginx认证文件

sudo vim /etc/nginx/sites-available/docker-registry

#文件中写入下面内容:

# For versions of Nginx > 1.3.9 that include chunked transfer encoding support
# Replace with appropriate values where necessary
 
upstream docker-registry {
 server localhost:5000;
}
 
server {
 listen 8080;
 server_name 192.168.32.139;
 
 # ssl on;
 # ssl_certificate /etc/ssl/certs/docker-registry;
 # ssl_certificate_key /etc/ssl/private/docker-registry;
 
 proxy_set_header Host       $http_host;   # required for Docker client sake
 proxy_set_header X-Real-IP  $remote_addr; # pass on real client 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 / {
     # let Nginx know about our auth file
     auth_basic              "Restricted";
     auth_basic_user_file    docker-registry.htpasswd;
 
     proxy_pass http://docker-registry;
 }
 location /_ping {
     auth_basic off;
     proxy_pass http://docker-registry;
 } 
 location /v1/_ping {
     auth_basic off;
     proxy_pass http://docker-registry;
 }
 
}
其中server_name改为主机的ip或域名


#链接配置文件到nginx

sudo ln -s /etc/nginx/sites-available/docker-registry /etc/nginx/sites-enabled/docker-registry 

#重启nginx服务

sudo service nginx restart


可以通过ip:8080来访问私有仓库了,并且有用户认证功能



Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐