为了更好的使用容器镜像,以及常见的收集习惯,尝试将dockerhub中的镜像,或者主要镜像同步到本地镜像仓库harbor。
同步的方法主要是

  1. 设定上游服务器docker.io,dockerproxy.com。缺点,两个都有限制。近期发现,AWS有ECS服务,地址public.ecr.aws
  2. 部署下游harbor服务器,本地可以访问。
  3. 设定一批待同步projects进入bash shell脚本的数组。
  4. 通过docker-ls访问上游服务器并拿到tag列表,也访问下游harbor服务器并达到已有的tag列表,如果没有就进行pull,然后push操作。

主要脚本内容如下:

#!/bin/bash
set -x
harbor1="public.ecr.aws"
harbor2="harbor.sddts.cn"
docker login -u admin -p "xxx" harbor.sddts.cn

projects=()
projects+=("library/mysql" "library/alpine" "library/centos" "library/debian" "library/ubuntu" "library/python" "library/caddy" "library/redis" "library/nginx" "library/busybox" "library/postgres" "library/node" "library/memcached" "library/httpd" "library/mongo" "library/rabbitmq" "library/mariadb" "library/docker" "library/hello-world" "library/openjdk" "library/golang" "library/registry" "library/wordpress" "library/php" "library/consul" "library/influxdb" "library/haproxy" "library/tomcat" "library/maven" "library/bash" "library/ghost" "library/kong" "library/zookeeper" "jenkins/jenkins" "library/mediawiki" "library/django" "library/gcc")
#projects+=("chaitin/safeline-tengine" "chaitin/safeline-mgt-api" "chaitin/safeline-detector" "chaitin/safeline-mario")
#projects+=("jumpserver/lion" "jumpserver/koko" "jumpserver/guacamole" "jumpserver/core" "jumpserver/jms_all" "jumpserver/web" "jumpserver/redis" "jumpserver/nginx" "jumpserver/core" "jumpserver/mysql" "jumpserver/magnus" "jumpserver/mariadb" "jumpserver/luna" "jumpserver/guacamole" "jumpserver/lina" "jumpserver/chen" "jumpserver/kael" "jumpserver/guacd" "jumpserver/python" "jumpserver/jms_web")
#projects+=("flashcatcloud/categraf" "flashcatcloud/nightingale" "flashcatcloud/ibex" "flashcatcloud/chatshot" "flashcatcloud/mock" "flashcatcloud/toolbox" "flashcatcloud/rocketmq-exporter" "flashcatcloud/public" "flashcatcloud/chrome" "flashcatcloud/scvpn" "flashcatcloud/scvpn" "flashcatcloud/wine" "flashcatcloud/kube-state-metric" "flashcatcloud/corplink" )
#projects+=("joyqi/typecho")
#projects+=("joyqi/typecho" )
#projects+=("rustdesk/rustdesk-server" )
#projects+=("dreamacro/clash" )
#projects+=("yidadaa/chatgpt-next-web" )
#projects+=("grafana/promtail" "grafana/loki" "grafana/loki-canary" "grafana/loki-docker-driver" "grafana/loki-build-image" "grafana/loki-operator" "grafana/loki-query-tee" "grafana/loki-canary-boringcrypto" "grafana/loki-helm-test" "grafana/loki-bigtable-backup" "grafana/logstash-output-loki" )
#projects+=("headscale/headscale" )
#projects+=("homeassistant/home-assistant" "homeassistant/raspberrypi3-homeassistant" "homeassistant/qemux86-64-homeassistant" )
#projects+=("jasonrivers/nagios" )
#projects+=("jenkinsci/jenkins" )
#projects+=("rancher/rancher-agent" "rancher/fleet-agent" "rancher/rancher" "rancher/server" "rancher/pause" "rancher/fleet" "rancher/mirrored-pause" "rancher/os" "rancher/metrics-server" "rancher/k8s" "rancher/local-path-provisioner" "rancher/agent" "rancher/klipper-lb" "rancher/shell" "rancher/rancher-operator" "rancher/rke-tools" "rancher/calico-node" "rancher/rancher-webhook" "rancher/coredns-coredns" "rancher/net" "rancher/mirrored-coredns-coredns" "rancher/nginx-ingress-controller" "rancher/klipper-helm" "rancher/hyperkube" "rancher/calico-cni" "rancher/mirrored-metrics-server" "rancher/mirrored-calico-node" "rancher/mirrored-istio-proxyv2" "rancher/istio-proxyv2" "rancher/coreos-flannel" "rancher/system-agent-installer-rke2" "rancher/gitjob" "rancher/lb-service-haproxy" "rancher/mirrored-prometheus-node-exporter" "rancher/network-manager" "rancher/mirrored-library-busybox" "rancher/metadata" "rancher/rke2-runtime" "rancher/k3s" "rancher/calico-pod2daemon-flexvol" "rancher/healthcheck" "rancher/dns" "rancher/mirrored-calico-cni" "rancher/mirrored-library-nginx" "rancher/prom-prometheus" "rancher/mirrored-calico-pod2daemon-flexvol" "rancher/prom-node-exporter" "rancher/fluentd" "rancher/log-aggregator" "rancher/cluster-proportional-autoscaler" "rancher/kube-api-auth" "rancher/system-agent-installer-k3s" "rancher/mirrored-library-traefik" "rancher/nginx-ingress-controller-defaultbackend" "rancher/jimmidyson-configmap-reload" "rancher/rancher-runtime" "rancher/library-traefik" "rancher/mirrored-flannelcni-flannel-cni-plugin" "rancher/mirrored-flannelcni-flannel" "rancher/coreos-prometheus-config-reloader" "rancher/grafana-grafana" "rancher/longhorn-manager" "rancher/scheduler" "rancher/library-busybox" "rancher/prometheus-auth" "rancher/mirrored-prometheus-operator-prometheus-config-reloader" "rancher/mirrored-prometheus-prometheus" "rancher/mirrored-cluster-proportional-autoscaler" "rancher/metrics-server-amd64" "rancher/security-scan" "rancher/istio-kubectl" "rancher/mirrored-calico-kube-controllers" "rancher/container-crontab" "rancher/mirrored-cloud-provider-vsphere-csi-release-driver" "rancher/mirrored-grafana-grafana" "rancher/coreos-prometheus-operator" "rancher/configmap-reload" "rancher/coreos-kube-state-metrics" "rancher/pushprox-client" "rancher/hardened-kubernetes" "rancher/mirrored-kiwigrid-k8s-sidecar" "rancher/system-upgrade-controller" "rancher/pushprox-proxy" "rancher/kubectl" "rancher/mirrored-prometheus-alertmanager" "rancher/k3s-upgrade" "rancher/mirrored-kube-state-metrics-kube-state-metrics" "rancher/pause-amd64" "rancher/mirrored-fluent-fluent-bit" "rancher/cis-operator" "rancher/coreos-etcd" "rancher/nginx" "rancher/mirrored-prometheus-operator-prometheus-operator" "rancher/library-nginx" "rancher/kiali-kiali" "rancher/prom-alertmanager" "rancher/mirrored-coreos-flannel" "rancher/hardened-etcd" "rancher/rke2-upgrade" "rancher/mirrored-longhornio-longhorn-manager" "rancher/hardened-coredns" "rancher/flannel-cni" "rancher/k3d-tools" "rancher/hardened-calico" "rancher/storage-secrets" "rancher/mirrored-prometheus-adapter-prometheus-adapter" "rancher/hardened-flannel" "rancher/jenkins-jenkins" "rancher/curlimages-curl" "rancher/hello-world" "rancher/mirrored-prom-alertmanager" "rancher/calico-kube-controllers" "rancher/mirrored-neuvector-updater" "rancher/tekton-utils" "rancher/k3d-proxy" "rancher/mirrored-jimmidyson-configmap-reload" "rancher/agent-instance" "rancher/coreos-configmap-reload" "rancher/external-dns" "rancher/kopf" "rancher/rke2-cloud-provider" "rancher/istio-mixer" "rancher/mirrored-coreos-etcd" "rancher/rancher-ecr-credentials" "rancher/mirrored-directxman12-k8s-prometheus-adapter" "rancher/hardened-cluster-autoscaler" "rancher/banzaicloud-fluentd" "rancher/mirrored-nginx-ingress-controller-defaultbackend" "rancher/mirrored-longhornio-longhorn-instance-manager" "rancher/mirrored-cloud-provider-vsphere-csi-release-syncer" "rancher/backup-restore-operator" "rancher/etcd" "rancher/mirrored-ingress-nginx-kube-webhook-certgen" "rancher/pipeline-tools" "rancher/mirrored-longhornio-csi-node-driver-registrar" "rancher/hardened-k8s-metrics-server" "rancher/system-agent-installer-rancher" "rancher/storage-nfs" "rancher/jaegertracing-all-in-one" "rancher/mirrored-banzaicloud-fluentd" "rancher/rio-controller" "rancher/mirrored-longhornio-longhorn-engine" "rancher/k8s-dns-sidecar-amd64" "rancher/k8s-dns-kube-dns-amd64" "rancher/minio-minio" "rancher/jenkins-jnlp-slave" "rancher/k8s-dns-dnsmasq-nanny-amd64" "rancher/istio-pilot" "rancher/k8s-dns-dnsmasq-nanny" "rancher/k8s-dns-sidecar" "rancher/k8s-dns-kube-dns" "rancher/machine" "rancher/mirrored-neuvector-scanner" "rancher/mirrored-banzaicloud-logging-operator" "rancher/mirrored-prom-prometheus" "rancher/istio-sidecar_injector" "rancher/istio-galley" "rancher/fluent-fluent-bit" "rancher/tiller" "rancher/mirrored-prom-node-exporter" "rancher/system-agent" "rancher/istio-citadel" "rancher/harvester" "rancher/eks-operator" "rancher/kiwigrid-k8s-sidecar" "rancher/mirrored-coreos-prometheus-config-reloader" "rancher/pipeline-jenkins-server" "rancher/k8s-dns-node-cache" "rancher/mirrored-longhornio-longhorn-ui" "rancher/cluster-proportional-autoscaler-amd64" "rancher/mirrored-calico-typha" "rancher/mirrored-k8s-dns-node-cache" "rancher/directxman12-k8s-prometheus-adapter-amd64" "rancher/mirrored-calico-operator" "rancher/mirrored-kiali-kiali" "rancher/mirrored-longhornio-csi-snapshotter" "rancher/mirrored-cloud-provider-vsphere-cpi-release-manager" "rancher/mirrored-longhornio-csi-attacher" "rancher/mirrored-longhornio-csi-resizer" "rancher/mirrored-longhornio-csi-provisioner" "rancher/os-docker" "rancher/mirrored-istio-install-cni" "rancher/mirrored-sonobuoy-sonobuoy" "rancher/mirrored-istio-pilot" "rancher/mirrored-minio-minio" "rancher/rio-dashboard" "rancher/fluentd-helper" "rancher/curl" "rancher/mirrored-cilium-cilium" "rancher/os-centosconsole" "rancher/kubernetes-external-dns" "rancher/longhorn-engine" "rancher/hardened-kube-proxy" "rancher/longhornio-longhorn-manager" "rancher/webhook-receiver" "rancher/mirrored-neuvector-enforcer" "rancher/kubectld" "rancher/mirrored-calico-ctl" "rancher/kubelet-pause" "rancher/lb-service-rancher" "rancher/mirrored-jettech-kube-webhook-certgen" "rancher/squareup-ghostunnel" "rancher/kubernetes-agent" "rancher/hardened-cni-plugins" "rancher/rio-autoscaler" "rancher/activator-2d008c4c36689d255523e5fa210c0bec" "rancher/swarmkit" "rancher/vm" "rancher/mirrored-sig-storage-snapshot-validation-webhook" "rancher/os-ubuntuconsole" "rancher/mirrored-sig-storage-snapshot-controller" "rancher/mirrored-openpolicyagent-gatekeeper" "rancher/banzaicloud-logging-operator" "rancher/externalip-webhook" "rancher/mirrored-cilium-operator-generic" "rancher/mirrored-sig-storage-livenessprobe" "rancher/os-headers" "rancher/cli" "rancher/calico-ctl" "rancher/mirrored-k8s-dns-dnsmasq-nanny" "rancher/mirrored-k8s-dns-sidecar" "rancher/k3d" "rancher/sonobuoy-sonobuoy" "rancher/mirrored-jaegertracing-all-in-one" "rancher/mirrored-k8s-dns-kube-dns" "rancher/longhornio-longhorn-ui" "rancher/mongodb-conf" "rancher/dind" "rancher/longhornio-csi-node-driver-registrar" "rancher/mirrored-sig-storage-csi-provisioner" "rancher/mirrored-sig-storage-csi-node-driver-registra" "rancher/mirrored-coreos-prometheus-operator" "rancher/mirrored-neuvector-controller" "rancher/mirrored-sig-storage-csi-attacher" "rancher/mirrored-k8scsi-livenessprobe" "rancher/mirrored-idealista-prom2teams" "rancher/opni-manager" "rancher/hardened-multus-cni" "rancher/mirrored-longhornio-longhorn-share-manager" "rancher/rancher-cleanup" "rancher/hardened-dns-node-cache" "rancher/socat-docker" "rancher/mirrored-k8scsi-csi-node-driver-registrar" "rancher/os-extras" "rancher/os-console" "rancher/harvester-network-controller" "rancher/vm-frontend" "rancher/os-debianconsole" "rancher/longhornio-csi-attacher" "rancher/os-base" )
#projects+=("andyshinn/dnsmasq" "mvance/unbound")
#projects+=("luode0320/web-start")
#projects+=("cloudnas/clouddrive2")
#projects+=("portainer/portainer")
#projects+=("hwdsl2/ipsec-vpn-server")
#projects+=("neilpang/acme.sh")
#projects+=("sdial/teleport")
#projects+=("mvance/unbound")

if [ ! -e /bin/docker-ls ]; then
  #wget https://vip.123pan.cn/1815238395/download/docker-ls/docker-ls-linux-amd64.zip -O /tmp/docker-ls.zip
  wget https://vip.123pan.cn/1815238395/download/docker-ls/docker-ls-windows-amd64.zip -O /tmp/docker-ls.zip
  unzip -d /bin/ /tmp/docker-ls.zip
fi

for project in "${projects[@]}"; do
  echo "开始新的project"
  sleep 0
  echo $project
  project="$project"
  project1="docker/$project"
  tagList=$(docker-ls tags -r https://$harbor1 $project1 2>/dev/null | grep '\- ' | tr -d '"' | awk '{print $2}')
  echo "tagList is $tagList"

  tagList2=$(docker-ls tags -r https://$harbor2 -u admin -p xxx $project 2>/dev/null | grep '\- ' | tr -d '"' | awk '{print $2}')
  echo "tagList2 is $tagList2"
  for tag in $tagList; do
    echo ""
    echo ""

    if  [ $(uname -m | grep x86_64 | wc -l )  -eq 1 ];then
      localArch="linux"
    fi

    if  [ $(uname -m | grep aarch64 | wc -l )  -eq 1 ];then
      localArch="arm"
    fi

    if [ "$tag" == "latest" ]; then
      echo "发现latest TAG标签"
      continue
    else
      if [ $(echo $tagList2 | grep $tag | wc -l) -eq 1 ]; then
        echo "tag $tag 已存在目标harbor中,本次跳过"
        continue
      else
        echo "tag $tag 不存在目标harbor中,本次继续"
      fi
    fi

    imageName1="$harbor1/$project1:$tag"
    imageName2="$harbor2/$project:$tag"

    echo ""
    echo "开始进行$imageName1镜像的下载。"
    while true; do
      docker pull "$imageName1"
      if [ $? -eq 0 ]; then
        echo "下载$imageName1正常。"
        echo "开始等待"
        sleep 0
        echo "等待结束,继续赶路!"
        break
      else
        echo "下载$imageName1异常。"
        echo "开始等待"
        sleep 0
        break
        echo "等待结束,继续尝试..."
      fi
    done

    docker tag $imageName1 $imageName2
    docker push $imageName2
#    docker rmi $imageName1 $imageName2
  done
  docker system prune -af
done

另外,同步过程中对linux、windows、arm同时支持。

2023-11-14T09:08:21.png

2023-11-14T09:09:07.png

2023-11-14T09:10:10.png

当前仓库200GB+。
2023-11-14T09:13:45.png

最后修改:2024 年 05 月 11 日
如果觉得我的文章对你有用,请随意赞赏