The docker container loses port forwarding after running benchmarks, it can be reproduced 100%.
Environment: 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
Is this a bug or expected behavior of docker?
UPDATE: This seems to be a long-standing problem https://github.com/moby/moby/issues/8817