0

I have containerized a simple PHP app. It needs to connect to the host's database (localhost) and do some operations. However, while running the app, I have the following error: Fatal error: Uncaught PDOException: SQLSTATE[HY000] [2002] No such file or directory ... My docker-compose file looks like this:

version: "3.9"
services:
  app:
    build: .
    stdin_open: true
    tty: true
    network_mode: "host"
    restart: on-failure

Looks like dockerized app can't connect with localhost database. I added network_mode: "host", but it didn't help.

I use Docker Desktop and Mac OS.

feyen01
  • 377
  • 5
  • 18
  • You are looking for host.docker.internal Take a look at this doc https://dev.to/natterstefan/docker-tip-how-to-get-host-s-ip-address-inside-a-docker-container-5anh – camba1 Mar 09 '21 at 16:48

1 Answers1

0

Instead of localhost I had to use docker.for.mac.localhost in my PHP script.

feyen01
  • 377
  • 5
  • 18