Using Docker I get the error: “SQLSTATE[HY000] [2002] No such file or directory”

If you face this error on your local then you need to change your DB configuration to run the project on local with docker.

Your docker config file might look like

version: '2'

services:
  web:
    build: ./docker/php
    ports:
      - 80:80
    volumes:
      - .:/var/www/html/
    links:
      - db
  db:
    build: ./docker/mysql
    ports:
      - 3306

In above settings (db:) this is your localhost so your database configuration will look like
database host: db
database username: root
database password : 12345

In short, you need to replace “localhost” with “db” and it’s done.

Leave a Reply