title: Symfony; SQLSTATE[HY000] [2002] No such file or directory while using 127.0.0.1 as database_host
body: <p>The full error is <code>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</code>, but that's too long for the title.</p>
  
  <p>I'm trying to set up a Symfony project locally, but I'm struggling to get the database connection to work. My <code>parameters.yml</code> looks as follows</p>
  
  <pre><code>parameters:
      database_host: 127.0.0.1
      database_port: 3306
      database_name: database_name
      database_user: username
      database_password: password
  </code></pre>
  
  <p>I've been googling this issue a lot and most people seem to solve the issue by changing <code>database_host</code> from <code>localhost</code> to <code>127.0.0.1</code>, 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.</p>
  
  <p>I've also tried multiple ways of setting up a Docker MySQL container, but can't get it to work. My <code>docker-compose.yml</code> looks like this;</p>
  
  <pre><code>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
  </code></pre>
  
  <p>But whenever I run <code>docker-compose up -d</code> I get the error <code>Unsupported config option for services: 'db'</code>.</p>
  
  <p>Another attempt was adding</p>
  
  <pre><code>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'
  </code></pre>
  
  <p>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 <code>docker-inspect</code> on the container to get the IP (172.17.0.3), but can't seem to get access to it. I can <code>exec</code> into it, login using <code>mysql -u root</code> and create the required user and database, but then I'm still struggling to actually connect to it.</p>
  
  <p>Running <code>docker ps</code> does show the sql container running btw;</p>
  
  <pre><code>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-&gt;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
  </code></pre>
  
  <p>I also thought it might be an issue with changes to the <code>parameters.yml</code> 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 <code>exec</code> I can see the changes in the <code>parameters.yml</code> file.</p>
  
  <p>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.</p>