我让服务器在docker下运行,并使用命令serve(app, listen='*:5000')启动它。
我可以:
127.0.0.1:5000和localhost:5000下在容器中访问它localhost:5000下从容器外部访问它我不能:
我试图将本地地址传递到serve命令中,但它会引发错误,说明无法访问该地址。同时也尝试了host='0.0.0.0'。帮不上忙。
有人知道怎么让它在我的机器外面显眼吗?
发布于 2020-11-02 04:55:28
好的,我找到了一个解决方案,似乎能解决这个问题。问题是wsl。在github wsl回购,有一个设置桥的脚本。下面我发布代码,这样它就不会消失。贷给埃文迪亚斯
$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";
}发布于 2020-10-31 06:05:25
如果您还没有这样做,请尝试公开端口5000。
这可以通过添加
EXPOSE 5000去你的码头文件。您还需要在您的服务中有host='0.0.0.0‘,以便能够从本地网络访问您的页面。
https://stackoverflow.com/questions/64618861
复制相似问题