简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM