由于国内的网络环境,和极其不做人的 docker,在 2024 年 10月这个时间点,在国内环境使用 docker 真的和吃翔一样难受。
写篇文章总结一下最近本地打镜像遇到的恶心经历,和解决方案。
解决方案
自建镜像源代理
git clone https://github.com/bboysoulcn/registry-mirror.git cd registry-mirror/docker/dockerhub docker-compose up -d
之后配置 nginx,可参考的配置文件:
server {
listen 80;
server_name example.site ;
root /home/wwwroot/example.site;
location ~ /.well-known {
allow all;
}
location ~ /\. {
deny all;
}
location / {
return 301 https://$host$request_uri;
}
access_log off;
}
server {
listen 443 ssl http2;
#listen [::]:443 ssl http2;
server_name example.site ;
root /home/wwwroot/example.site;
ssl_certificate /usr/local/nginx/conf/ssl/example.site_ecc/fullchain.cer;
ssl_certificate_key /usr/local/nginx/conf/ssl/example.site_ecc/example.site.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers "TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5";
ssl_session_cache builtin:1000 shared:SSL:10m;
ssl_dhparam /usr/local/nginx/conf/ssl/dhparam.pem;
location ~ /.well-known {
allow all;
}
location ~ /\. {
deny all;
}
location / {
proxy_pass http://127.0.0.1:5000;
client_max_body_size 1000m;
}
access_log off;
}
然后修改 ~/.docker/daemon.json
注意
本文描述的是 MacOS 上的解法,其他 OS 配置文件的路径可能不一样
➜ ~ cat ~/.docker/daemon.json
{
"builder": {
"gc": {
"defaultKeepStorage": "20GB",
"enabled": true
}
},
"experimental": false,
"registry-mirrors": ["https://example.site"]
}
国内镜像源的问题
我大 XX 自有国情在此
镜像非常的不全。以阿里云为例,pull 一个 jdk 基础镜像,例如 docker pull amazoncorretto:21.0.5-alpine,都会报 403 Forbidden。
Docker 本地代理的问题
http/https 代理不生效
下面的方法都不行。
5342 docker build . --build-arg HTTP_PROXY=socks5://127.0.0.1:11111 --build-arg HTTPS_PROXY=socks5://127.0.0.1:11111 -f DockerfileBase -t some.site/abc/def:1.2.3 5344 docker build . --build-arg HTTP_PROXY=http://xx:xx@1.2.3.4:4321 --build-arg HTTPS_PROXY=http://xx:xx@1.2.3.4:4321 -f DockerfileBase -t some.site/abc/def:1.2.3
socks5 代理居然需要企业级订阅??
Docker,你是真不要脸啊。一个 socks5 代理的功能你敢收 24 刀一个月。


本作品使用基于以下许可授权:Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.