自建dockerhub registry,解决国内docker镜像无法使用的问题.

大前提:有一个自己的海外vps!

version: "3.8"

services:
  registry-proxy:
    image: registry
    restart: unless-stopped
    ports:
      - 5000:5000
    volumes:
      - ./data:/var/lib/registry
      - ./config.yml:/etc/docker/registry/config.yml

config.yml

version: 0.1
log:
  fields:
    service: registry
storage:
  cache:
    blobdescriptor: inmemory
  filesystem:
    rootdirectory: /var/lib/registry
  delete:
    enabled: true
http:
  addr: :5000
  headers:
    X-Content-Type-Options: [nosniff]
health:
  storagedriver:
    enabled: true
    interval: 10s
    threshold: 3
proxy:
  remoteurl: https://registry-1.docker.io

nginx配置

server {
        listen              2443 ssl;
        server_name  xxx.xxx.com;
        ssl_certificate     /etc/nginx/ca/xxx.com/fullchain1.pem;
        ssl_certificate_key /etc/nginx/ca/xxx.com/privkey1.pem;
        ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers         HIGH:!aNULL:!MD5;
         
  proxy_set_header Host   $http_host;
  proxy_set_header X-Real-IP $remote_addr;
  client_max_body_size 0;              
  chunked_transfer_encoding on;
  add_header 'Docker-Distribution-Api-Version' 'registry/2.0' always;

    location / {
       auth_basic off;
       proxy_set_header Host       $http_host;
       proxy_set_header X-Real-IP    $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Proto $scheme;
       proxy_read_timeout         900;
       proxy_pass http://127.0.0.1:5000;
  }

 

  location /_ping {
    auth_basic off;
    proxy_pass http://127.0.0.1:5000;
  }
  location /v2/_ping {
    auth_basic off;
    proxy_pass http://127.0.0.1:5000;
  }
  location /v2/_catalog {
    auth_basic off;
    proxy_pass http://127.0.0.1:5000;
  }

}

然后按这个nginx地址,配置docker的registry-mirrors 即可

24 Likes

感谢!

1 Like

感谢分享,备用了

2 Likes

搞七捻三常规话题

看到有人用work实现类似的

现在好难搞啊

上海交大的无了,刚建完你出教程了。。。

就是昨天发现镜像全挂了,就搞得这个
阿里云的镜像也挂了

压力给到daocloud了,目前已知能用的唯一一个不需要注册直接用的,南大的镜像更新不及时。

可能未来还要面对更多. :thinking:

不知道一个docker会影响什么。。。

常规话题软件分享

:+1: :+1: :+1: :+1:

太难了,备用

简化版的docker-compose

services:
  registry:
    image: registry:latest
    container_name: registry
    volumes:
      - ./data:/var/lib/registry
    restart: unless-stopped
    ports:
      - "127.0.0.1:5000:5000"
    environment:
      TZ: Asia/Shanghai
      REGISTRY_PROXY_REMOTEURL: https://registry-1.docker.io

备用备用

感谢佬,收藏备用

备用

+3

牛,Mark了

学习学习