自建Docker镜像加速服务
docker 9

1.将以下2个文件放在同级目录下

docker compose up -d


1.docker-compose.yaml

services:
  ## docker hub
  dockerhub:
    container_name: reg-docker-hub
    image: dqzboy/registry:latest
    restart: always
    environment:
      - OTEL_TRACES_EXPORTER=none
      #- http=http://host:port
      #- https=http://host:port
    volumes:
      - ./registry/data:/var/lib/registry
      - ./registry-hub.yml:/etc/distribution/config.yml
      #- ./htpasswd:/auth/htpasswd
    ports:
      - 51000:5000
    networks:
      - registry-net



networks:
  registry-net:
2.registry-hub.yml

version: 0.1
log:
  fields:
    service: registry
storage:
  filesystem:
    rootdirectory: /var/lib/registry
  #inmemory: #此存储驱动程序不会在运行期间保留任何数据,适合磁盘空间下的机器使用(但是会使用内存开销,只适合测试)
  delete:
    enabled: true
  cache:
    blobdescriptor: inmemory   
    blobdescriptorsize: 10000
  maintenance:
    uploadpurging:
      enabled: true
      age: 168h
      interval: 24h
      dryrun: false
    readonly:
      enabled: false
http:
  addr: :5000
  headers:
    X-Content-Type-Options: [nosniff]
    Access-Control-Allow-Origin: ['*']
    Access-Control-Allow-Methods: ['HEAD', 'GET', 'OPTIONS', 'DELETE']
    Access-Control-Allow-Headers: ['Authorization', 'Accept', 'Cache-Control']
    Access-Control-Max-Age: [1728000]
    Access-Control-Allow-Credentials: [true]
    Access-Control-Expose-Headers: ['Docker-Content-Digest']

health:
  storagedriver:
    enabled: true
    interval: 10s
    threshold: 3

proxy:
  remoteurl: https://registry-1.docker.io
  username: 
  password:
  ttl: 168h 

2.使用方法

1.直接修改配置文件并重启docker

vim /etc/docker/daemon.json
{
    "registry-mirrors": [ "https://hub.your_domain_name" ]
}

2.使用自建的 Registry 地址替换官方的 Registry 地址拉取镜像

# docker hub Registry
## 源:nginx:latest
## 替换
docker pull hub.your_domain_name/library/nginx:latest

自建Docker镜像加速服务
https://blog.883051.xyz/archives/zi-jian-dockerjing-xiang-jia-su-fu-wu
作者
玉溪
发布于
更新于
许可