title: Mysqli Error 2002: no such file or directory
body: <p>I am trying to run nginx, php, mysql together with docker.</p>
  
  <p>When i run docker-compose, everything looks fine, but when i try to make a connection to mysql via php code in my index page i'm getting this error.</p>
  
  <pre><code>Warning: mysqli::__construct(): (HY000/2002): No such file or directory in /code/index.php on line 8
  Connection failed: No such file or directory
  </code></pre>
  
  <ul>
  <li>I have tried changing localhost to 127.0.0.1 and both with :3306 after it.</li>
  </ul>
  
  <p><strong>When changing localhost --> 127.0.0.1, i'm getting another connection failed statement:</strong></p>
  
  <pre><code>Warning: mysqli::__construct(): (HY000/2002): Connection refused in /code/index.php on line 8
  Connection failed: Connection refused
  </code></pre>
  
  <p><strong>php code:</strong></p>
  
  <pre><code>&lt;?php
  
  $servername = "localhost";
  $username = "root";
  $password = "toor";
  
  // Create connection
  $conn = new mysqli($servername, $username, $password);
  
  // Check connection
  if ($conn-&gt;connect_error) {
      die("Connection failed: " . $conn-&gt;connect_error);
  }
  echo "Connected successfully";
  
  echo phpinfo();
  
  ?&gt;
  </code></pre>
  
  <p>Also when i look at <code>phpinfo();</code>, there is no value given to <code>mysqli.default_socket</code>.</p>
  
  <p>when going into the mysql image after starting docker-compose, i'm able to go into mysql shell and execute commands just fine.</p>
  
  <p>Any help is appreciated!</p>