The full error is Doctrine\DBAL\Exception\ConnectionException: An exception occurred in driver: SQLSTATE[HY000] [2002] No such file or directory in /app/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php on line 113, but that's too long for the title.
I'm trying to set up a Symfony project locally, but I'm struggling to get the database connection to work. My parameters.yml looks as follows
parameters:
    database_host: 127.0.0.1
    database_port: 3306
    database_name: database_name
    database_user: username
    database_password: password
I've been googling this issue a lot and most people seem to solve the issue by changing database_host from localhost to 127.0.0.1, but this doesn't work for me. The app itself runs via Docker, but I've set up the database connection once via Brew and once with a MySQL server for Mac. In both cases I can connect via the command line and with SequelPro/TablePlus, but whenever I try to access the website through the browser I get the "No such file or directory" error.
I've also tried multiple ways of setting up a Docker MySQL container, but can't get it to work. My docker-compose.yml looks like this;
nginx:
  build: nginx
  ports:
    - "8080:80"
  links:
    - php
  volumes:
    - ../:/app
php:
  build: php-fpm
  volumes:
    - ../:/app
  working_dir: /app
  extra_hosts:
    - "site.dev: 172.17.0.1"
services:
  db:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_DATABASE: 'database_name'
      MYSQL_USER: 'username'
      MYSQL_PASSWORD: 'password'
      MYSQL_ROOT_PASSWORD: 'password_root'
    ports:
      - '3306:3306'
    expose:
      - '3306'
    volumes:
      - my-db:/var/lib/mysql
But whenever I run docker-compose up -d I get the error Unsupported config option for services: 'db'.
Another attempt was adding
mysql:
  image: mysql:latest
  volumes:
    - mysql_data:/var/lib/mysql
  environment:
    - MYSQL_ROOT_PASSWORD='password'
    - MYSQL_DATABASE='database_name'
    - MYSQL_USER='username'
    - MYSQL_PASSWORD='password'
To the docker-compose file, and while it does build the mysql image, I can't seem to connect to it with SequelPro/TablePlus. I ran docker-inspect on the container to get the IP (172.17.0.3), but can't seem to get access to it. I can exec into it, login using mysql -u root and create the required user and database, but then I'm still struggling to actually connect to it.
Running docker ps does show the sql container running btw;
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES
b6de6030791d        docker_nginx        "nginx -g 'daemon of…"   19 minutes ago      Up 14 minutes       0.0.0.0:8080->80/tcp   docker_nginx_1
f26b832bb005        docker_php          "docker-php-entrypoi…"   19 minutes ago      Up 14 minutes       9000/tcp               docker_php_1
6c2a9e657435        mysql:latest        "docker-entrypoint.s…"   19 minutes ago      Up 14 minutes       3306/tcp, 33060/tcp    docker_mysql_1
I also thought it might be an issue with changes to the parameters.yml file not properly syncing with the container as I'm using Mac (at my old workplace we had to use docker-sync to make sync changes between our dev environment and the actual container), but when inspecting the container itself using exec I can see the changes in the parameters.yml file.
Could the issue be it trying to connect to a mysql server running outside the Docker container? I'm still very new to Docker so I wouldn't be surprised if that's the mistake. Any tips are appreciated 'cause I'm at a dead end.
 
     
    