镜像加速器

博客分类: docker 阅读次数: comments

镜像加速器

##

1、registry镜像用一个

2、config.yaml用多个,主要的不同就是代理url不一样

3、起多个registry:azure,阿里云。后端存储用一个,

中科大镜像太慢,有时候不稳定,不建议用

4、vm中,修改/etc/docker/daemon.json中registry-mirrors配三条url

{
	"registry-mirrors": ["http://10.154.12.120:7997","http://10.154.12.120:7998","http://10.154.12.120:7999"]
}

5、config.yaml的配置

默认配置查看链接:

https://github.com/docker/docker.github.io/blob/v18.03/registry/configuration.md ;这边有参数的解释

version: 0.1
log:
  fields:
    service: registry
  level: info
storage:
  cache:
    blobdescriptor: redis
  s3:#存储配置
    accesskey: admin
    secretkey: 8cDcos11
    region: huadong
    regionendpoint: http://10.154.12.127:9000
    bucket: mirror-registry
    encrypt: false
    secure: false
    v4auth: true
    chunksize: 5242880
    rootdirectory: /
  delete:
    enabled: true
  maintenance:
    uploadpurging:
      enabled: true
      age: 168h
      interval: 24h
      dryrun: false
    readonly:
      enabled: false
http:
  addr: :5000
  headers:
    X-Content-Type-Options: [nosniff]
redis:
  addr: 10.154.12.248:6379
  password: 8cDcos11
  db: 0
  dialtimeout: 10ms
  readtimeout: 10ms
  writetimeout: 10ms
  pool:
    maxidle: 16
    maxactive: 64
    idletimeout: 300s
health:
  storagedriver:
    enabled: true
    interval: 10s
    threshold: 3
proxy:
  remoteurl: https://docker.mirrors.ustc.edu.cn
  #这边可替换成其他加速地址:https://dockerhub.azk8s.cn;https://cduvuqsh.mirror.aliyuncs.com
  

6、Dockerfile

FROM registry:latest
LABEL maintainer="zhouyu <zhouyu@cmss.chinamobile.com>"
COPY entrypoint.sh /entrypoint.sh 
COPY config.yml /etc/docker/registry/config.yml

7、entrypoint.sh

#!/bin/sh

set -e

CONFIG_YML=/etc/docker/registry/config.yml

if [ -n "$PROXY_REMOTE_URL" -a `grep -c "$PROXY_REMOTE_URL" $CONFIG_YML` -eq 0 ]; then
    echo "proxy:" >> $CONFIG_YML
    echo "  remoteurl: $PROXY_REMOTE_URL" >> $CONFIG_YML
    echo "------ Enabled proxy to remote: $PROXY_REMOTE_URL ------"
elif [ $DELETE_ENABLED = true -a `grep -c "delete:" $CONFIG_YML` -eq 0 ]; then
    sed -i '/rootdirectory/a\  delete:' $CONFIG_YML
    sed -i '/delete/a\    enabled: true' $CONFIG_YML
    echo "------ Enabled local storage delete -----"
fi

case "$1" in
    *.yaml|*.yml) set -- registry serve "$@" ;;
    serve|garbage-collect|help|-*) set -- registry "$@" ;;
esac

exec "$@"

8、docker-compose.yml

version: '2'
services:
 registry-azure: 
   image: registry-mirror-azure:v1.0
   volumes:
     - /root/registry-mirror-fishing/registry-mirror-master/config.yml:/etc/docker/registry/config.yml
   ports:
     - 7998:5000

9、启动命令

docker run -itd -p 7997:5000 -v `pwd`/config.yml:/etc/docker/registry/config.yml  -e PROXY_REMOTE_URL=https://dockerhub.azk8s.cn  --name registry-keda registry-mirror-keda:v1.0

指定下配置文件