Docker: intercept outbound traffic and change ip:port to another container

  docker, docker-compose, linux, networking

First of all, i wanna say that i don’t have much experience in advance networking on Linux.

A have a task to deploy our .deb packages in containers, and applications are mostly tunned for operating on localhost while being designed with capability of operating on set of server machines (DB, application, client, etc), but since components of app have been distributed between containers, i need to make it work together. The goal is to do it w/o any pre-setup sequences that change IP address in configs for components, since target IP is uncertain and IP alias in /etc/hosts may not solve the problem.

Could i somehow intercept outbound connection to localhost:6432 and froward it to, we say, <ip_alias>:6432 with abillity to correctly recieve incoming traffic from resource we forwarded to? Can you give me some example of script?

Source: Docker Questions