Docker容器允许我 curl 主机端口80,但不允许 curl 其他端口

tv6aics1  于 2022-11-13  发布在  Docker
关注(0)|答案(1)|浏览(208)

所以我有一个服务在我的localhost:80 , and localhost:8080中运行
我需要从码头集装箱里拿出来
因此,我在我的docker容器cli中输入并尝试以下命令。

curl http://www.example.com //a famous website --> works
curl 172.17.0.1 ---> works , this is fetching my hosts localhost port 80 , its the default docker interface and resolves on the host
curl 172.17.0.1:1112 ---> I can fetch this , i have a simple express server running there returning a hello world in my local machine , it can also be curled from withing the host with a curl localhost:1112

上面你可以看到我使用172.17.0.1连接到我的主机从我的容器,而不是本地主机,因为本地主机将意味着本地连接说,容器,这不是我寻找的。
现在问题来了以下。
我在我的端口8888中创建了一个到另一台机器的ssh隧道,它只能通过在我的主机上运行的vpn来访问。

ssh -fN myname@database.pl -L 8888:db.env.prise:80

这创建了一个隧道,我可以 curl 在我的主机localhost:8888如果我尝试从我的主机内

curl -s http://localhost:8888/test | jq

它正确地获取了一个json,所以我们的想法是在我的容器中做一些类似的事情。

curl http://172.17.0.1:8888/test
Failed to connect to 172.17.0.1 port 8888: Connection refused

这就是我收到的错误。
为什么我可以获取每一个端口,除了一个?我怀疑这可能与我的码头没有在VPN中?
我怎么能解决这个问题。
我有一个openvpn文件的连接,但仅此而已。
虽然我真的不认为它的vpns的错,因为如果我 curl 从我的localhost与vpn断开, curl 将失败,但至少它试图 curl 它被卡住了一段时间.而试图 curl 该端口从码头内立即得到拒绝.

7fyelxc5

7fyelxc51#

看起来您正在尝试从Docker连接到只能通过主机上的SSH访问的资源。
此问题的有效解决方案是通过以下方式将外部计算机的端口转发到您的计算机:
您的位置:凡人谷知道〉教育/myname@database.pl〉
这会将外部端口重定向到本地端口。问题是Docker无法访问此端口。
使用socat,您可以打开一个新端口,该端口监听所有接口,而不仅仅是本地接口:
Socat TCP侦听器:8889,派生,绑定=0.0.0.0.0 TCP:本地主机:8888
通过此端口,连接将被重定向到您的目标计算机:
8889-〉8888-〉80

相关问题