Docker Community Forums

Share and learn in the Docker community.

Use Docker Container as Gateway for another Container

Hey folks,

already searched the net but Im a bit confused about using a container as gateway.
I have an image from docker hub running on a pi 4 that provides http https socks5 proxy with routing traffic through a vpn. I use it for my other lan devices to provide them a vpn tunnnel.
Now Im planning to build a new container with raspbian image as base and I want this container to use the “vpn container” as a gateway.
What would be the way to achieve this? Realized that in the raspbian image/container there is no network interface to configure oO. Or could it be done with docker network settings?

Basically what you want to do is create a docker network and join both of your containers to it.
Then they will have an interface with which they can communicate

Thx for your reply.
So I create a new bridged network and tell both containers to use this as interface?
But I want to route all traffic from container B through container A.
Could you explain a bit more in depth please?
Also wondering why the raspbian container has no iface…

In the previous lessons, we learned a great deal about Docker, Dockerfile, Docker images, and Docker containers. We understood the isolated nature of a Docker container and how to connect with a running container using -p (or --publish) flag to map a host port to a container port for network access or -v (or --volume) flag to access files of a container from the host.
In this lesson, we are going to talk about the networking aspect of the containerization process. We will explore what different options Docker gives us to control the network of a Docker container and how we can use them depending on our needs.
A Docker network is a medium through which a Docker container can talk to its host, other containers on the host, or any other machines on or outside the host’s network. To configure networks, we use the $ docker network command that provides us subcommands such as ls, create, attach to configure networks and containers’ relationship to them.