title: Connect to MySQL on localhost from Docker container
body: <p>I have mysql running on my localhost
  I can connect it by running:</p>
  
  <pre><code>mysql -h 127.0.0.1 -P 3306 -u root -p
  </code></pre>
  
  <p>I also ran docker container with command:</p>
  
  <pre><code>docker run -tid -v $(pwd):/code -p 3306:3306 -p 5000:5000 --name container container
  </code></pre>
  
  <p>And I want to access my Mysql db from docker container. So I also type from docker container:</p>
  
  <pre><code>mysql -h 127.0.0.1 -P 3306 -u root -p
  </code></pre>
  
  <p>But it gives me error:</p>
  
  <pre><code>ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)
  </code></pre>
  
  <p>What am I doing wrong? Ports seems to be correct.
  <strong>EDIT 1</strong>
  Output of <code>ifconfig</code> in docker:</p>
  
  <pre><code>eth0      Link encap:Ethernet  HWaddr 02:42:ac:11:00:02  
            inet addr:172.17.0.2  Bcast:0.0.0.0  Mask:255.255.0.0
            inet6 addr: fe80::42:acff:fe11:2/64 Scope:Link
            UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
            RX packets:1780 errors:0 dropped:0 overruns:0 frame:0
            TX packets:977 errors:0 dropped:0 overruns:0 carrier:0
            collisions:0 txqueuelen:0 
            RX bytes:2225781 (2.2 MB)  TX bytes:56572 (56.5 KB)
  
  lo        Link encap:Local Loopback  
            inet addr:127.0.0.1  Mask:255.0.0.0
            inet6 addr: ::1/128 Scope:Host
            UP LOOPBACK RUNNING  MTU:65536  Metric:1
            RX packets:28 errors:0 dropped:0 overruns:0 frame:0
            TX packets:28 errors:0 dropped:0 overruns:0 carrier:0
            collisions:0 txqueuelen:1 
            RX bytes:1400 (1.4 KB)  TX bytes:1400 (1.4 KB)
  </code></pre>