首页 > 解决方案 > docker 容器在运行基准测试后丢失端口转发

问题描述

docker 容器在运行基准测试后丢失端口转发,可以 100% 重现。

环境:Ubuntu 20.04.1 LTS,docker 19.03.11,wrk 4.1.0

docker run -d -p 8080:80 --name my-nginx nginx:1.18

netstat -ntulp | grep 8080
# tcp6    0     0    :::8080     :::*     LISTEN  6237/docker-proxy

# at the beginning of this benchmark, my-nginx can still be accessed through localhost:8080
wrk -t12 -c1000 -d30s http://localhost:8080

netstat -ntulp | grep 8080
# empty

wrk -t12 -c1000 -d30s http://localhost:8080
# unable to connect to localhost:8080 Connection refused

# get my-nginx's ip
docker inspect my-nginx
# my-nginx can be accessed through container_ip:80
wrk -t12 -c1000 -d30s http://172.17.0.2:80

这是 docker 的错误还是预期行为?

更新:这似乎是一个长期存在的问题https://github.com/moby/moby/issues/8817

标签: dockerubuntu

解决方案


推荐阅读