title: Can't access MySQL database in Docker container from another container
body: <p>I have MySQL 5.7 container pulled from here: <a href="https://hub.docker.com/_/mysql/" rel="nofollow noreferrer">https://hub.docker.com/_/mysql/</a></p>
  
  <p>Here's how I run it:</p>
  
  <pre><code>docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=pwd -d mysql:5.7
  </code></pre>
  
  <p>It works good, I'm able to connect to MySQL db from my host machine.</p>
  
  <p>However, when I try to run another container with <code>mysql</code> container linked like this:</p>
  
  <pre><code>docker run --link mysql:mysql -p 8080:8080 -d app:dev
  </code></pre>
  
  <p>my container can't connect to <code>mysql</code>:</p>
  
  <pre><code># 172.17.0.3 is mysql's ip taken from /etc/hosts of another container.
  mysql -h 172.17.0.3 -u root -ppwd
  
  ERROR 2003 (HY000): Can't connect to MySQL server on '172.17.0.3'
  </code></pre>
  
  <p>I tried to use docker networks but I'm getting the same error.</p>
  
  <p>Here's <code>nmap -p 3306 172.17.0.2</code> output:</p>
  
  <pre><code>Starting Nmap 7.01 ( https://nmap.org ) at 2018-06-03 08:34 UTC
  Nmap scan report for e66874413058 (172.17.0.2)
  Host is up (0.00012s latency).
  PORT     STATE  SERVICE
  3306/tcp closed mysql
  
  Nmap done: 1 IP address (1 host up) scanned in 0.39 seconds
  </code></pre>
  
  <p>For unknown reason, the port is closed. If I run <code>nmap</code> command from my host, it's open.</p>
  
  <p>How to connect to MySQL server from another docker container?</p>