Imagine I have this setup:
- An application server
- Private IP:
1.0.0.1
; Private hostname:machine1.internal.domain
- Public IP :
2.0.0.1
; Public hostname :machine1.example.com
- Private IP:
- A database server
- Private IP:
1.0.0.2
; Private hostname:machine2.internal.domain
- Public IP :
2.0.0.2
; Public hostname :machine2.example.com
- Private IP:
These 2 machines are in a DMZ.
Machine1 needs to connect to machine2 using the internal hostname. One thing is important: we don't want any traffic between these two to go outside the DMZ.
And hostname machine2.internal.domain
is hardcoded in the application running on machine #1.
Without Dockerized setup:
- Case#1: If name resolution works for
machine2.internal.domain
, everything is good already. - Case#2: Otherwise, I would add an entry in
/etc/hosts
in machine1:machine2.internal.domain 1.0.0.2
With Dockerized setup I know when name resolution doesn't work, Docker container cannot reach machine2 since it doesn't inherit entries in /etc/hosts
of host machine.
How can I make this thing working the best way? ... for both cases: DNS resolving working and not working.
I have reviewed following options for case 2:
- Passing the IP of machine2 to Docker container in machine1:
docker run --add-host machine2.internal.domain:1.0.0.2 ...
- I have to define IP of
machine2.internal.domain
twice: once in/etc/hosts
and once in Docker run command
- I have to define IP of
- Not containarizing network for container in machine1:
docker blabla --net=host
- This doesn't feel right although I can't tell what the consequences would be.