'How to achieve flow like this

I'd like to get flow like this one on the picture. Is there any way to intercept all HTTP request within a docker container, modify their headers and then send them? Notice that URI of first request is pointing to APP 4, not APP 2.enter image description here



Solution 1:[1]

Docker doesn't directly support what you're describing. The only networking setup it really supports out-of-the-box has a private per-application network with NAT to the host; if you think you need some sort of more complicated topology, or traffic interceptors, or automatic proxies, you're in "build it by hand" territory.

In the diagram you show, two things jump out at me. "App 1" and "App 2" are shown as in the same container, and that's rarely a best practice. Each component is shown with a localhost URL but that's also a mildly subtle topic (inside a Docker container, the container itself is localhost).

A very typical setup doesn't use automatic traffic interception per se, but just has external clients target some sort of reverse proxy. That looks a little more like

+- Docker network ----------------------+
| +- Container -+     +- Container -+   |
| | Application | <-- | Nginx Proxy | <---- Client
| +-------------+     +-------------+   |
+---------------------------------------+

You might start this stack with

docker network create appnet
docker run --net appnet --name application my/application
docker run --net appnet --name nginx_proxy -p 8081:80 my/nginx

Since the two containers are on the same Docker network, the nginx configuration can proxy_pass http://application/;. Because of the -p option, external clients can reach http://host.example.com:8081/ and it goes to the proxy.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 David Maze