获取Docker-Registry
docker pull registry:0.6.7
配置Docker-Registry
mkdir /datadisk/data/registrymkdir /datadisk/data/registry/confmkdir /datadisk/data/registry/data
vim /datadisk/data/registry/conf/config.yml
config.yml
:
common: loglevel: info secret_key: _env:SECRET_KEYdev: storage: local storage_path: /registry-data
启动Docker-Registry
REGISTRY=$(docker run -d -i -t --dns x.x.x.x --expose 80 -v /datadisk/data/registry/conf:/registry-conf -v /datadisk/data/registry/data:/registry-data -e REGISTRY_PORT=80 -e DOCKER_REGISTRY_CONFIG=/registry-conf/config.yml -e SETTINGS_FLAVOR=dev registry)
请将DNS换成您自己的DNS服务器
此处只所以要使用私有DNS的原因是因为我们希望用简短的域名访问这个服务,比如
repos.rd
,但是这个域名又不存在,所以我们需要这个私有DNS服务器做解析,当然如果我们的域名是公有的,或直接使用IP,则不需要设置,否则会出现http://repos.rd/v1/_ping: i/o timeout
获取这个Container的IP
docker inspect -format '{ { .NetworkSettings.IPAddress }}' $REGISTRY
配置NGINX
sudo vim /etc/nginx/sites-enabled/docker-registr.conf
请确保/etc/nginx/nginx.conf有include /etc/nginx/sites-enabled/*.conf
这条语句
upstream docker-registry { server 172.30.0.4:80; # docker-registry}server { listen 80; server_name repos.rd; # private local netework name 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 #proxy_set_header Authorization ""; client_max_body_size 0; # disable any limits to avoid HTTP 413 for large image uploads location / { proxy_pass http://docker-registry; }}
重启 NGINX
sudo service nginx restart