title: netcat for MySQL connection forwarding
body: <p>This question is in relation to</p>
  
  <p><a href="https://stackoverflow.com/questions/30886633/dockerized-web-app-connecting-to-mysql-db-on-host">Dockerized web app connecting to MySQL DB on host</a></p>
  
  <p>I am trying to open up a connection from a docker container to the host to support MySQL connections.</p>
  
  <p>The way I understand it I should be able to execute the following in my container</p>
  
  <pre><code>nc.traditional -l -p 3306 -c "nc.traditional 172.17.42.1 3306" &amp;
  </code></pre>
  
  <p>to open up a tunnel from the Docker container port 3306 to the host (IP 172.17.42.1) MySQL instance, running on port 3306.</p>
  
  <p>Trouble is as soon as I try to connect from the container</p>
  
  <pre><code>mysql --host=127.0.0.1 --port=3306 -uroot -ppassword
  </code></pre>
  
  <p>I get an error and the tunnel exits</p>
  
  <pre><code>root@7ec710b77baf:/var/log# mysql --host=127.0.0.1 --port=3306 -uroot -pAcc355
  (UNKNOWN) [172.17.42.1] 3306 (mysql) : Connection refused
  ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0
  [1]+  Exit 1                  nc.traditional -l -p 3306 -c "nc.traditional 172.17.42.1 3306"
  </code></pre>
  
  <p>Why would the tunnel exit?  What am I doing wrong? It certainly seems to contact the MySQL instance as I get a different error message when I try a different port.</p>
  
  <p>I haven't been able to find any info in logs or on std out to help.</p>
  
  <p>Any ideas?</p>