How to allow docker containers in a subnet to communicate outside the subnet

191 views Asked by At

I have a Windows host running a RHEL 8 VM that is running multiple Docker containers. I created the Docker network and assigned static IPs for each container. The VM can access each container endpoints. However, the Windows host and anything outside cannot. Is it possible to create a subnet that will allow applications from the outside to communicate with the containers?

Each of these container is acting as a routing device to receive data from an external application. The external app needs to be able to send the data to the IP that correspond to the container.

NOTE: currently not using docker-compose

2

There are 2 answers

0
Moziii On

Here's a step-by-step setting up a subnet for Docker containers in a Rhel 8 VM on a Windows host, to allow external applications to communicate with these containers:

  • Set up a bridge network in Docker to connect all containers.
  • Ensure each Docker container has a static IP assigned within the bridge network.
  • Configure port forwarding on the Rhel VM to redirect traffic from the VM to the Docker containers.
  • Adjust the Windows host network settings to allow traffic to the Rhel VM.
  • Set up forwarding rules on both the Windows host and Rhel VM to allow external applications to reach the Docker containers.
0
Chris Becke On

External connectivity in docker is managed by publishing ports ports.

Yes, containers with static IPs can be accessed from the host OS. This is not an intended feature, this is an implementation detail of bridge networks.

If you do insist on using this detail, then be aware that its going to work only on docker engine installs, Docker Desktop is not going to help expose the containers from the Moby vm to the host. Because it is not actually a feature of Docker.