I'm trying to use Docker as part of my testing suite. I have 2 containers set up as:
version: "3"
services:
mongo_3_4:
image: mongo:3.4
command: ["mongod", "--smallfiles"]
ports:
- "27021:27017"
frontend:
build:
context: ./Dockerfiles/path/
dockerfile: Dockerfile
ports:
- "63175:63175"
The frontend
has the ability to mount a mongoDb where I have to give it credentials of host and port, for example locally I would use localhost | 27021
and my db would be mounted.
The only way I can get it to currently work, is by getting the IP of the host machine. I achieved this by doing as described here : $ ipconfig getifaddr en0
thus getting the host machine IP and using it for mounting my db from the frontend ie 192.168.1.42 | 27021
The problem I have is this host IP will be different on various environments as it's used as part of a test suite. It would be used on various local machines with different OS's and say Travis-ci.
Is there a recommended way to hard code this host IP from within docker or would I have to create a script that works out the host and do this sudo ifconfig lo0 alias 192.168.46.49
?
Just seem overly complicated when all I'm doing is having 2 containers and wanting one of them to be able to mount the db from the other?