问题是这样的。我得到了一个由pyinstaller制作的zip文件。在该文件中有一个设置,使服务器只侦听localhost server.add_insecure_port(f'localhost:{port_num}')
。我想从centos docker运行这个python文件。Docker在WSL2上运行。
到目前为止,我能够运行docker,但问题如下:我可以从WSL2(在我的例子中是ubunty)对localhost:port进行grpcUrl调用。但是当我尝试从windows cmd调用这些函数时,我得到以下错误:Failed to dial target host "localhost:9111": dial tcp [::1]:9111: connectex: No connection could be made because the target machine actively refused it.
或此Failed to dial target host "127.0.0.1:9111": dial tcp 127.0.0.1:9111: connectex: No connection could be made because the target machine actively refused it.
我已经使用--network="host"
启动了docker,希望它能帮助我,但它只能帮助ubuntu进行grpcUrl调用,而不能帮助windows。
任何帮助将不胜感激。请注意,我不能将localhost更改为0.0.0.0...
1条答案
按热度按时间6yoyoihd1#
SSH隧道是我的答案。
在WSL上安装SSH服务器:
sudo apt install openssh-server
sudo vi /etc/ssh/sshd_config
->在末尾插入下一个块搜索文件中的任何其他
PasswordAuthentication
并将其设置为yes
。1.创建ssh密钥
1.添加脚本以在启动
vi ~/.bashrc
时运行SSH->在文件末尾插入下一个块1.让ssh服务器在没有密码的情况下运行
sudo visudo
->在文件末尾插入下一个代码1.从CMD运行
wsl --shutdown
重新启动WSL ->并再次打开wsl(例如通过运行ubuntu)从CMD
wsl hostname -I
获取wsl - run的ip现在从CMD
ssh -L 127.0.0.1:<port>:localhost:<port> <wsl username>@<ip from wsl hostname -I> -p 2222
运行