I know many people has requested similar questions, but none of the solutions I found, could be applied on my case. I am sure the solution should be simple, but I cannot really find it!
Basically I need to access a specific service running on my host machine from a docker container (dmz). I have a pool of docker containers and an " orchestrator" service that runs on the real machine (host). This guy is a python REST service running at port 5001 of the host and it is responsible, for example, to save the execution logs of the running docker machines, among others. I need one specific machine to be able to access the host (the dmz), but not the others! If they need to talk to the host they need to pass through the dmz.
======================================================================
|1- HOST -> 5002:5002 dmz(dockerContainer):5002/service1 |
|2- dmz(container) <--> 9200:9200 elasticsearch(container):9200 |
|3- HOST:5002/service2 <- 5001:5001 dmz(dockerContainer) |
======================================================================
The connections 1 and 2 work. They are rest services and I get even the answer of the rest request. The 3 is what I need to do now, and I don' t mange to! I don' t know what happened, but I swear to god, three weeks ago from the containers I could access the host by its real IP address, and now I cannot anymore! I have no idea what has changed but just before I could and now I cannot anymore.
- What I have tried so far:
- Access the host via its real IP, that worked in the past (swear to god, it did). I get a TimeoutError: [Errno 110] Connection timed out
- Access the docker0 172.17.0.1 (https://nickjanetakis.com/blog/docker-tip-65-get-your-docker-hosts-ip-address-from-in-a-container). The same TimeoutError: [Errno 110] Connection timed out. And that is even good, because it would mean that the other containers would also be able to do that, and I don't want that anyone could access the server like that!!
- Add the host in the extra-hosts (https://forums.docker.com/t/accessing-host-machine-from-within-docker-container/14248/5) - Does not allow both predefined and user-defined networks to be used at the same time... and I need it.
- Port forwarding ( maybe the direction, but I don't see how to do it on the container-> host direction) Add a port for the host machine to the docker. It works on the host-> container direction, adding 5002:5002 on the port of the composer file, but the oposit it is not possible. When I start the network, I cannot put my service up anymore (it is reasonable, since the port is not available). How to use that? I mean on the docker to host sense? How could I point the port forwarding to a service that is up and running?
Any Ideas of how to do that?!?!?
OS Version/build : Ubuntu 16.04
Docker version : 19.03.2, build 6a30dfc
Docker-compose version : 1.24.0, build 0aa59064
Composer file:
version: '3.5'
services:
dmz:
container_name: testbed_dmz
# 1 - DMZ image name
image: testbed_dmz:latest
ports:
# 2 - DMZ ports
- "5002:5002"
networks:
data_network:
# 3 - DMZ ip address
ipv4_address: 192.168.7.2
elasticsearch:
container_name: data_server
# 4 - Elasticsearch image name
image: docker.elastic.co/elasticsearch/elasticsearch:7.0.0
environment:
- cluster.name=docker-cluster
- bootstrap.memory_lock=true
- discovery.type=single-node
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
ports:
- "9200:9200"
networks:
data_network:
# 5 elasticsearch ip address
ipv4_address: 192.168.7.3
kibana:
container_name: testbed_kibana
# 6 kibana image name
image: docker.elastic.co/kibana/kibana:7.0.0
environment:
# 7 again the elasticsearch ip address
- SERVER_NAME=192.168.7.3
ports:
- "5601:5601" networks:
data_network:
# 8 kibana ip address
ipv4_address: 192.168.7.4
networks:
data_network:
# 9 the name of the network
name: DMZ_DATA_NET
driver: bridge
ipam:
driver: default
config:
# 10 the network address
- subnet: 192.168.7.0/29