title: Docker Mysql Can't connect to local MySQL server through socket
body: <p>I'm using below command to run the mysql docker container.</p>
  
  <pre><code>docker container run -it --name mysql-test -e MYSQL_ROOT_PASSWORD=secret mysql bash
  </code></pre>
  
  <p>Then I tried to connect to mysql inside docker container using below command.</p>
  
  <pre><code>mysql -uroot -psecret
  </code></pre>
  
  <p>It gives me below error.</p>
  
  <pre><code>ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
  </code></pre>
  
  <p>If I do below then sometimes it works but not all time.</p>
  
  <pre><code>touch /var/run/mysqld/mysqld.sock
  </code></pre>
  
  <p>Then I tried to run the container in detach mode but it also gave me the same error.</p>
  
  <pre><code>docker container run -d -p 3306:3306 --name mysql-test -e MYSQL_ROOT_PASSWORD=secret mysql
  docker exec -it mysql-test bash
  mysql -uroot -p
  </code></pre>
  
  <p>What am I doing wrong here?</p>