joakimb
joakimb

Reputation: 563

Routing Docker traffic through a container

I am trying to achieve the following in docker:

Before:

Internet --> Host --> ContainerA

After:

Internet --> Host --> ContainerB --> ContainerA

Clients are communicating with a server instance on ContainerA. Now I want to place ContainerB in between the host and ContainerA. Communication with ContainerA should now only be possible through ContainerB. I.e. direct network communication between host and ContainerA should be disallowed, as should communication between other containers and ContainerA.

I know how I can setup communication between ContainerA and ContainerB but how do I block direct communication to ContainerA from the host or other Containers.

Upvotes: 2

Views: 1753

Answers (1)

Yaron Idan
Yaron Idan

Reputation: 6765

It depends on the tool you are using to deploy your containers. Assuming you are talking about a vanilla docker engine you can achieve this with docker-compose. Create a network consisting of only ContainerA and ContainerB, and expose only the ports in ContainerB to the host and the rest of the world.

Let me know if that makes sense to you, if you need more guidance specify that in the comments and I'll try to create an example docker-compose.yaml for such a configuration.

Upvotes: 1

Related Questions