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"

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

when I put network_mode: host and configure the databases ip to 172.17.0.1 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?

Hi.

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.