停靠的烧瓶/女服务员在本地网络中不可见

时间:2020-10-31 05:58:08

标签: docker flask waitress

我的服务器在docker下运行,并使用命令serve(app, listen='*:5000')启动它。

我可以:

  • 127.0.0.1:5000localhost:5000的容器下访问它
  • localhost:5000下的容器外部访问它

我不能:

  • 从“ 127.0.0.1:5000”下的外部容器访问它
  • 使用本地ip从本地网络访问它(这对我来说最重要)

我试图将本地地址传递给serve命令,但是它抛出错误,表明该地址无法访问。还尝试了host='0.0.0.0'。没有帮助。

有人会知道如何使它在我的机器外部可见吗?

2 个答案:

答案 0 :(得分:0)

好的,所以我找到了解决问题的办法。问题是WSL。 在github wsl repo ,有一个脚本设置了桥梁。 下面我发布代码,所以它不会消​​失。 归功于edwindijas

$found = $remoteport -match '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';

if( $found ){
  $remoteport = $matches[0];
} else{
  echo "The Script Exited, the ip address of WSL 2 cannot be found";
  exit;
}

#[Ports]

#All the ports you want to forward separated by coma
$ports=@(80,443,10000,3000,5000);


#[Static ip]
#You can change the addr to your ip config to listen to a specific address
$addr='0.0.0.0';
$ports_a = $ports -join ",";


#Remove Firewall Exception Rules
iex "Remove-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' ";

#adding Exception Rules for inbound and outbound Rules
iex "New-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' -Direction Outbound -LocalPort $ports_a -Action Allow -Protocol TCP";
iex "New-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' -Direction Inbound -LocalPort $ports_a -Action Allow -Protocol TCP";

for( $i = 0; $i -lt $ports.length; $i++ ){
  $port = $ports[$i];
  iex "netsh interface portproxy delete v4tov4 listenport=$port listenaddress=$addr";
  iex "netsh interface portproxy add v4tov4 listenport=$port listenaddress=$addr connectport=$port connectaddress=$remoteport";
}

答案 1 :(得分:-1)

如果尚未这样做,请尝试公开端口5000。

这可以通过添加

来完成
EXPOSE 5000

到您的Dockerfile。您还需要在服务中添加host ='0.0.0.0'才能从本地网络访问您的页面。