Concordus Applications
Concordus Applications

Reputation: 987

Iptables to forward remote port to local port for local access

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).

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?

Upvotes: 0

Views: 1415

Answers (1)

qkrijger
qkrijger

Reputation: 27226

If you expose the port for your DB to 3306 on the host using docker run -name database -p 127.0.0.1:3306:49155 <DB_image> <cmd> as explained on http://docs.docker.io/en/latest/use/port_redirection/#port-redirection.

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?

You would not need iptables if that works.

Upvotes: 3

Related Questions