title: Cannot connect to mysql in Docker container from host
body: <p>I'm running a Docker mysql container on my Mac laptop. Previously I was able to connect to it from the host OS with the mysql client. However, somehow it got deleted, and now after I re-created it, I can no longer to connect to it. I've searched dozens of similar questions, but am completely stumped.</p>
  
  <p>Here's how I created it:</p>
  
  <pre><code>docker container run --name mysql-zhxw-dev -p 3306:3306 --expose=3306 -v zhxw-local-db-:/var/lib/mysql -e MYSQL_ALLOW_EMPTY_PASSWORD=yes -d mysql:5.7.30
  </code></pre>
  
  <p>Every time I run <code>mysql -u root -h 127.0.0.1</code> the following from my host OS, I get:</p>
  
  <pre><code>ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (61)
  </code></pre>
  
  <p>I can login to the container, and connect to mysql from within:</p>
  
  <pre><code>docker container exec -it mysql-zhxw-dev bash
  mysql -u root &lt;-- connects fine
  </code></pre>
  
  <p>I've tried:</p>
  
  <ul>
  <li>Omitting the named volume</li>
  <li>Specifying a password</li>
  <li>Various versions of mysql, including 5.6 and 5.7</li>
  <li>Logging in to the container with <code>docker container exec</code>, installing <code>vi</code>, editing /etc/mysql/mysql.conf.d/mysqld.cnf and uncommenting the line that contains <code>bind-address</code>. I tried it with both <code>bind-address = 0.0.0.0</code> and <code>bind-address = 127.0.0.1</code>, then obviously exiting and running <code>docker container restart mysql-zhxw-dev</code>.</li>
  <li>Specifying port to connect to with <code>-P 3306</code></li>
  <li>Connecting with <code>-h localhost</code>, <code>-h 127.0.0.1</code>, <code>-h 0.0.0.0</code>, and omitting the <code>-h</code></li>
  <li>Specifying <code>--protocol=TCP</code> when connecting</li>
  </ul>
  
  <p>I'm at a loss as to what else to try.</p>