开发中会遇到ip地址不方便暴露的情况。

解决方法见: https://stackoverflow.com/questions/27810076/how-do-i-access-a-server-on-localhost-with-nginx-docker-container

核心是--add-host

You can get your current IP address as shown here: ifconfig en0 | grep inet | grep -v inet6 | awk '{print $2}' Then you can use the --add-host flag with docker run: docker run --add-host localnode:$(ifconfig en0 | grep inet | grep -v inet6 | awk '{print \$2}') ... In your proxypass use localnode instead of localhost.

尝试可行:

#登录
docker run  -it  --rm --add-host localhost:$(ifconfig en0 | grep inet | grep -v inet6 | awk '{print $2}')  nginx bash
#安装ping 
apt-get update 
apt-get install inetutils-ping
#测试
ping localhost