title: SQLSTATE[HY000] [2002] Connection refused. Laravel API hosted on Docker with WSL2 Ubuntu 18.04
body: <p>I am trying to create a new item via postman to my laravel app ran in docker. The docker containers are auto-generated via ddev which provides a development environment and ran using WSL2 Ubuntu 18.04. So here is the catch, I can &quot;php artisan migrate&quot; just fine I can even &quot;php artisan tinker&quot; and create one just fine but when sending request via postman from my host machine I get this error.</p>
  <blockquote>
  <p>Illuminate\Database\QueryException: SQLSTATE[HY000] [2002] Connection refused (SQL: select count(*) as aggregate from <code>users</code> where <code>id</code> = 1) in file /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connection.php on line 671</p>
  </blockquote>
  <p>I had solved this issue yesterday with this <a href="https://www.craigforrester.com/posts/windows-subsystem-for-linux-disable-ipv6-for-apt/" rel="nofollow noreferrer">https://www.craigforrester.com/posts/windows-subsystem-for-linux-disable-ipv6-for-apt/</a> but tried it when I got this error again today and no luck.</p>
  <p><strong>Things I've Tried:</strong></p>
  <ul>
  <li>Setting <strong>DB_HOST</strong> to 127.0.0.1, wsl_ip, docker_gateway_ip, docker_mysql_ip, localhost, mysql. And actually I get the same error on all of them except localhost, which makes sense.</li>
  <li>Forcing ipv4 <a href="https://www.craigforrester.com/posts/windows-subsystem-for-linux-disable-ipv6-for-apt/" rel="nofollow noreferrer">https://www.craigforrester.com/posts/windows-subsystem-for-linux-disable-ipv6-for-apt/</a></li>
  <li>Changing gai.conf settings <a href="https://www.reddit.com/r/bashonubuntuonwindows/comments/7u1le5/disable_ipv6_or_prefer_ipv4_first/" rel="nofollow noreferrer">https://www.reddit.com/r/bashonubuntuonwindows/comments/7u1le5/disable_ipv6_or_prefer_ipv4_first/</a></li>
  <li>Changing grub config <a href="https://askubuntu.com/questions/1046057/disabling-ipv6-in-ubuntu-server-18-04">https://askubuntu.com/questions/1046057/disabling-ipv6-in-ubuntu-server-18-04</a></li>
  </ul>
  <p><strong>What I Think It Is:</strong>
  I am 99% certain this is not a credentials issue and more so a routing issue, cause like I said in the first paragraph I can migrate and create from the WSL Ubuntu. I think the routing issue is either from my host to the WSL or from WSL to mysql. But then again my request seems to be going through otherwise I wouldve got some kind of PHP connection error and not a MySQL connection error</p>