I have two different services on one server up and running with docker.
One service contains metabase with following docker-compose file.
metabase:
container_name: metabase
image: metabase/metabase:latest
ports:
- "3102:3000"
extra_hosts:
- "host.docker.internal:host-gateway"
volumes:
- metabase-data:/metabase
And another service contains mongo db:
mongodb:
image: mongo:4.4
restart: always
ports:
- ${MONGODB_PORT:-27017}:27017
volumes:
- mongodb-data:/data/db
environment:
MONGO_INITDB_ROOT_USERNAME: ${MONGODB_USERNAME}
MONGO_INITDB_ROOT_PASSWORD: ${MONGODB_PASSWORD}
I tried host.docker.internal , my server public address, localhost etc but nothing works. and always receive connection timeout.
Netcat test is sucessfull from my local machine
nc -v 212.xx.xxx.175 27017
Connection to 212.xx.xxx.175 27017 port [tcp/*] succeeded!
But tried these in metabase container and all of them ends up with 'operation timed out'
nc -v host.docker.internal 27017
nc: host.docker.internal (172.17.0.1:0): Operation timed out
I also can access my database from mongo compass app, (so im pretty sure it's not about firewall) but no chance when using metabase.
Update: Creating bridge network in one docker-compose and use it as external network in another, works. My main question is why it doesn't work with my public address or host.docker.internal?
If both of the service exist in the same
docker-compose.ymlfile then they can communicate via the Docker network using the service name as their DNS name.Now from within the running Metabase container you can do:
and it will open a connection to the MongoDB container on port 27017.
Screenshot below shows:
ncconnection to MongoDB container andYou will probably need to sort out SSL for the connection to the database, but that is another matter!