Docker Community Forums

Share and learn in the Docker community.

MySQL Server inaccessible fromoutside of container


(Oakenshield213) #1

Hello,
Attempting to connect to a MySQL-Server within a Container fails with the error message:

ERROR 2013 (HY000): Lost connection to MySQL server at ‘reading initial communication packet’, system error: 0

I have read a lot about port forwarding etc. but non brought me closer to a solution:

Host-System:

Ubuntu 16.03 LTS Xenial
Docker version 17.12.0-ce, build c97c6d6

Docker-Image:

docker run -d -p 4051:3306 -p 4001:80 --name test -v test_var:/var oakenshield213/mediawiki:latest

I can login from within the container:

mysql -u root -h 127.0.0.1 --password=changeme -P 3306 mysql

It fails when attempting to connect from the host:

mysql -u root -h 127.0.0.1 --password=changeme -P 4051 mysql
ERROR 2013 (HY000): Lost connection to MySQL server at ‘reading initial communication packet’, system error: 0

Just to check: I will get a different error when attempting another port, e.g. 4052.

mysql -u root -h 127.0.0.1 --password=changeme -P 4052 mysql
ERROR 2003 (HY000): Can’t connect to MySQL server on ‘127.0.0.1’ (111)

The port mapping seems to be running

docker container ls
[…] 0.0.0.0:4001->80/tcp, 0.0.0.0:4051->3306/tcp […]

Is there anything I may have missed?

Best,

Rüdiger