title: Symfony docker container can't connect to Mysql
body: <p>My stack is quite common, one container for my Symfony app, another one for Mysql.
  For some reason, Symfony can't connect to Mysql container with following error :</p>
  
  <blockquote>
    <p>Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'</p>
  </blockquote>
  
  <p>A simple php file to test the MySQL connection, on the Symfony container works with this</p>
  
  <pre><code>&lt;?php
  $dbh = new PDO('mysql:host=database;dbname=mysite', 'mysite', 'password');
  </code></pre>
  
  <p>Here is my Symfony parameters file:</p>
  
  <pre><code>database_driver: pdo_mysql
  database_host: database
  database_port: 3306
  database_name: mysite
  database_user: mysite
  database_password: password
  </code></pre>
  
  <p>And here is my docker-compose file : </p>
  
  <pre><code>site:
    build: webapp
    ports :
       - "80:80"
    volumes:
       - /home/myuser/dev/mysite:/var/www/html/
    links:
       - database
  
  database:
    image: mysql:5.5
    ports:
      - "3306:3306"  
    environment:
      - MYSQL_ROOT_PASSWORD=password
      - MYSQL_DATABASE=mysite
      - MYSQL_USER=mysite
      - MYSQL_PASSWORD=password
  </code></pre>
  
  <p>I also tried with a fresh Symfony project without error.</p>