How to access the host machine in Docker Compose

My node application connects to two databases, postgresql and redis. I want to make container only of my node.

I can’t get my node container to connect to postgres and redis on my host machine.

I already configured redis and postgres to allow the connection, I even tested it from a virtual machine and it is allowing it.

Below my docker-compose file

version: "3"

     build: .
     image: mkevison/server
     command: node server.js
     container_name: betlim
      - "3000:3333"
     restart: always

when I put network_mode: host and configure the databases ip to in my .env file it works, but that way I can’t map the ports

I’ve also tried setting the host ip in .env file to host.docker.internal and it doesn’t work either
I saw somewhere that host.docker.internal doesn’t apply to linux

How do I resolve this?


You can either use the IP of the host, or use “docker inspect APP-CONTAINER” to see which gateway ip it uses, which will be the docker host.

Thanks! So simple and I hadn’t thought of that, it worked perfectly.