iptables将远程端口转发到本地端口以进行本地访问 [英] Iptables to forward remote port to local port for local access

查看:448
本文介绍了iptables将远程端口转发到本地端口以进行本地访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Docker容器中的应用程序中有一个应用程序。我在另一个Docker容器中有数据库。 DB容器的暴露端口为49155。应用程序要求数据库暴露在端口3306上,由于IonCube混淆,我无法更改它。因此,我可以将应用程序很好地指向数据库容器,但是应用程序找不到数据库(错误的端口)。

I have an application in an application in Docker container. I have the DB in another Docker container. The DB container has an exposed port of 49155. The application requires that the database be exposed on port 3306 and I can't change that thanks to IonCube obfuscation. So, I can point my application to the database container just fine, but the application can't find the DB (wrong port).

我最初的解决方案是给我们IPTables使用以下命令将端口3306上的本地请求转发到端口49155上的远程容器:

My initial solution was to us IPTables to forward local requests on port 3306 to the remote container on port 49155 using:

iptables -t nat -A PREROUTING -p tcp --src 127.0.0.1 --dport 3306 -j REDIRECT --destination 192.168.200.212 --to-ports 49155

仍然无法正常工作。有什么想法吗?

Still not working. Any thoughts?

推荐答案

如果使用 docker run将DB的端口公开到主机上的3306 -名称数据库-p 127.0.0.1:3306:49155< DB_image> < cmd> ,如 http中所述: //docs.docker.io/zh-CN/latest/use/port_redirection/#port-redirection

然后如果您运行的应用程序链接到数据库,如 http://上所述docs.docker.io/zh-CN/latest/use/working_with_links_names/ 我认为应用程序容器的3306端口具有数据库端口?

And if you then run your app linking to database as explained on http://docs.docker.io/en/latest/use/working_with_links_names/ I would assume the app container has the DB port on 3306?

您不需要iptables,如果可行。

You would not need iptables if that works.

这篇关于iptables将远程端口转发到本地端口以进行本地访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆