侧边栏壁纸
博主头像
★街角晚灯★博主等级

博观而约取 厚积而薄发

  • 累计撰写 466 篇文章
  • 累计创建 185 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

Docker镜像代理配置

WinJay
2024-09-26 / 0 评论 / 0 点赞 / 30 阅读 / 4715 字 / 正在检测是否收录...
温馨提示:
文章发布较早,内容可能过时,阅读注意甄别。。。。

docker 镜像代理配置

image-20240926105236984

因为Docker 官方源很早之前就被官方封禁了,国内拉取 Docker 镜像必须依赖国内镜像源:比如网易、中科大、阿里等。
但是最近大家应该都遇到了无法拉取 Docker 镜像的问题,即使换了国内源也会拉取失败。就我目前的测试来看:国内的 Docker 镜像源疑似集体停止服务。而且这一切发生得静悄悄,没有任何相关公告。 虽然可以通过部分镜像源拉取历史版本(阿里 2022之前的版本镜像),为了从根本解决问题。
本文,将为docker配置上代理(梯子),解决docker镜像拉取问题,获取最新镜像文件。

docker 版本查询

[root@Server-60 PDF]# docker info
Client: Docker Engine - Community
 Version:    25.0.4
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.13.0
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.24.7
    Path:     /usr/libexec/docker/cli-plugins/docker-compose

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 3
 Server Version: 25.0.4
 Storage Driver: overlay2
  Backing Filesystem: xfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: ae07eda36dd25f8a1b98dfbf587313b99c0190bb
 runc version: v1.1.12-0-g51d5e94
 init version: de40ad0
 Security Options:
  seccomp
   Profile: builtin
 Kernel Version: 3.10.0-1160.108.1.el7.x86_64
 Operating System: CentOS Linux 7 (Core)
 OSType: linux
 Architecture: x86_64
 CPUs: 8
 Total Memory: 31.26GiB
 Name: Server-60
 ID: 32893237-176c-4458-bf0f-0f65b4f6f29e
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Registry Mirrors:
  https://d3is0bty.mirror.aliyuncs.com/
  http://f1361db2.m.daocloud.io/
 Live Restore Enabled: false

[root@Server-60 PDF]# docker version
Client: Docker Engine - Community
 Version:           25.0.4
 API version:       1.44
 Go version:        go1.21.8
 Git commit:        1a576c5
 Built:             Wed Mar  6 16:33:16 2024
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          25.0.4
  API version:      1.44 (minimum version 1.24)
  Go version:       go1.21.8
  Git commit:       061aa95
  Built:            Wed Mar  6 16:32:11 2024
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.28
  GitCommit:        ae07eda36dd25f8a1b98dfbf587313b99c0190bb
 runc:
  Version:          1.1.12
  GitCommit:        v1.1.12-0-g51d5e94
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

准备代理IP

可以某宝购买,也可以是自己搭建的TZ;这里介绍 从 clash 中分享出来的代理,开启来自局域网的连接。

image-20240926103150520

为docker 配置代理

  • 修改文件vim /etc/docker/daemon.json ,配置内容为下文,没有则新建

删除之前配置的国内镜像源,配置docker 官方镜像链接。这里直接粘贴进去即可。

 {
     "registry-mirrors": ["https://hub.docker.com"],
     "insecure-registries": ["http://hub.WinJay.cn"],
     "storage-driver": "overlay2",
     "log-driver":"json-file",
     "log-opts": {"max-size":"5m", "max-file":"3"}
 }

image-20240926103622774

创建代理文件

mkdir /etc/systemd/system/docker.service.d
vim /etc/systemd/system/docker.service.d/proxy.conf
[Service]
# 172.16.0.88为代理服务器IP地址
Environment="HTTP_PROXY=http://172.16.0.88:7890"
Environment="HTTPS_PROXY=http://172.16.0.88:7890"
Environment="NO_PROXY=localhost,127.0.0.1"

加载配置、重启docker

# 加载配置
systemctl daemon-reload
# 重启docker
systemctl restart docker
# 查看代理配置是否生效
systemctl show --property=Environment docker
##---打印内容---
Environment=HTTP_PROXY=http://172.16.0.88:7890 HTTPS_PROXY=http://172.16.0.88:7890

image-20240926103855764

效果测试

  • 配置代理前

image-20240926103414842

  • 配置代理后

image-20240926104537213

0
  1. 支付宝打赏

    qrcode alipay
  2. 微信打赏

    qrcode weixin

评论区