Quantcast
Channel: Active questions tagged dockerfile - DevOps Stack Exchange
Viewing all articles
Browse latest Browse all 136

Can't connect to local mongoDB from Docker Container

$
0
0

I have mongodb running in the host machine (Ubuntu 23.04) in the default port. I have set the bind_ip to be 0.0.0.0. In my docker-compose file, I have added

extra_hosts:      - "host.docker.internal:host-gateway"

And, I have my mongodb URI as mongodb://host.docker.internal/mydbname. However, I get Server selection timed out after 30000 ms

I tried to change network_type as host, after that it started working but why is this host.docker.internal working? Kindly please help.

Edit:This is the docker-compose.yml

version: "3.3"services:  web:    image: test    container_name: test    restart: always    build:        context: .    extra_hosts:      - "host.docker.internal:host-gateway"    ports:       - "9345:5000"    command: node app.js    env_file:      - backend/.env.production      - frontend/.env.production

Viewing all articles
Browse latest Browse all 136

Trending Articles