我有一个客户端和服务器应用程序。服务器侦听TCP localhost:3344
地址,客户端发送消息给localhost:3344
。在同一主机上运行它们时工作正常。
如果服务器在docker容器上运行且客户端在主机上运行,则服务器不会收到任何消息。不知道如何设置网络,以便容器侦听主机的localhost。我尝试以下方法:
docker run -it --expose 3344 -p 127.0.0.1:3344:3344 run-server
这只会为你做的工作:
docker run -it -p 3344:3344 <docker repository name> run-server