联通云docker版nginx断流之迷

问题描述

学校新给的云主机,本质就是ecs
安装docker版的nginx之后出现断流现象
具体现象描述如下:
在云主机内访问校内其他资源,典型命令如下:

1
curl http://nic.pages.tongji.edu.cn/developerhub-frontend/static/index.css

是可以的。但是进入到docker容器内部,使用同样的命令去访问资源,会有一定概率卡死,这个原因未知。

附上一个测试脚本以备后续使用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/bin/bash

url="http://nic.pages.tongji.edu.cn/developerhub-frontend/static/img/bg.jpg"
total_requests=50
success_count=0
total_time=0

for ((i=1; i<=$total_requests; i++)); do
start_time=$(date +%s.%N)
response=$(curl -s -o /dev/null -w "%{http_code}" "$url")
end_time=$(date +%s.%N)

if [ "$response" == "200" ]; then
success_count=$((success_count+1))
fi

request_time=$(echo "$end_time - $start_time" | bc)
total_time=$(echo "$total_time + $request_time" | bc)

echo "Request $i: Response $response Time $request_time"
done

average_time=$(echo "scale=2; $total_time / $total_requests" | bc)
success_rate=$(echo "scale=2; ($success_count * 100) / $total_requests" | bc)

echo "Average Response Time: $average_time seconds"
echo "Success Rate: $success_rate%"

解决方案

使用docker网络模式里的host模式,也算是比较常见的解决方案

1
docker run -d --net=host git.tongji.edu.cn:5050/nic/nic-tool/developerplatform/nginx:latest

根因分析

不知道具体原因,只能大概猜想一下是网卡原因导致的