docker 镜像代理配置
因为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
中分享出来的代理,开启来自局域网的连接。
为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"}
}
创建代理文件
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
效果测试
- 配置代理前
- 配置代理后
评论区