0

This question is in relation to

Dockerized web app connecting to MySQL DB on host

I am trying to open up a connection from a docker container to the host to support MySQL connections.

The way I understand it I should be able to execute the following in my container

nc.traditional -l -p 3306 -c "nc.traditional 172.17.42.1 3306" &

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.

Trouble is as soon as I try to connect from the container

mysql --host=127.0.0.1 --port=3306 -uroot -ppassword

I get an error and the tunnel exits

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"

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.

I haven't been able to find any info in logs or on std out to help.

Any ideas?

Community
  • 1
  • 1
YanisTheYak
  • 373
  • 5
  • 14
  • 1
    There's no need for any tunnel probably. You just need to expose MySQL port 3306 to other local port. May be 3306 as well. – Opal Jun 17 '15 at 18:48
  • see http://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach/24326540#24326540 – Thomasleveil Jun 17 '15 at 22:52

1 Answers1

0

From my experience you're probably after socat rather than netcat.

eg

socat TCP-LISTEN:3306,fork TCP:db-host:3306

I've found issues with netcat handling the connection

Timothy c
  • 751
  • 7
  • 8