自建DockerHub registry

lijunyi2024-06-07DockerDocker

自建DockerHub registry

  • 通过自建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
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
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地址,配置dockerregistry-mirrors 即可

Last Updated 6/14/2024, 3:05:31 AM