Reputation: 989
I have a web frontend application which communicates via a specific port (REST API) with a backend application (lets call it "My_App"). My_App needs to send Multicast frames to communicate with something in the outside world. And I need to put everything into Docker Containers.
First I tried to have nginx and the app inside a single Container using host networking for the whole Container. Like depicted in the following picture:
This works on my developement PC but does not on the target system due to some firewall rules preventing me from accessing Port 8081 and 12345 from outside the target system. If I log into the target system e.g. via ssh I can access those Ports just fine. So the situation on the target system is like that:
So now I am trying to split the app and nginx into separate Containers (Port Mapping for bridged networks is allowed on the host system and I can access maped Ports from the outside).
What I want to to do is connect a Container A
using Bridge Networking with another Container B
using host networking, so that an Application (e.g. Nginx as reverse Proxy) inside Container A
can send Requests to Container B
on a specific Port. Something like shown in the following picture:
But now I do not know how to achieve this. I know that I can communicate between Containers if both are using bridge Networking by using Dockers DNS and the name of each Container. But how to do this if one Container uses host networking, bypassing Dockers DNS?
Here is my current docker-compose file:
version: "2"
services:
Container_B:
image: my_app
network_mode: host
Container_A:
image: nginx:alpine
ports:
- 80:8081
- 12342:12342 // apparently does not work because in use by Container_B
depends_on:
- "Container_B"
Is it possible to access a Port, inside a Container_B
using host networking, from within a Container_A
using Bridge networking? Without some external application doing the routing?
Upvotes: 2
Views: 1577
Reputation: 440
If you are on Mac or Windows, you can use host.docker.internal
to connect to containers in network_mode: 'host'
.
For linux, this feature is not available yet. It will be available in the new release of docker. Till then, you can use a docker image dockerhost (docker pull qoomon/docker-host
) and connect to containers in host mode using dockerhost:{port}
method.
add this in your docker-compose.yml file:
dockerhost:
image: qoomon/docker-host
cap_add:
- NET_ADMIN
- NET_RAW
restart: on-failure
networks:
- back_end
Container_A should also be in the same network as dockerhost.
After this, you can connect to containers from within bridge network to containers in host mode using dockerhost:{port}
where port is where container in host is listening to.
Upvotes: 1