9

I pulled MySQL container from Dockerhub and it is running on my macbook pro as you can see as follow

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
12cd3deaa3f0        mysql:latest        "/entrypoint.sh mysql"   47 hours ago        Up 10 minutes       3306/tcp            mysqldb

Then I downloaded the MySQL workbench and I tried to connect it with MySQL container, but it does not work. It shows connection error.

Your connection attempt failed for user 'root' from your host to server at 192.168.99.102:3306:
Can't connect to MySQL server on '192.168.99.102' (60)

The IP from docker machine is

docker-machine ip default
192.168.99.100

and the port from MySQL is 3306 as you can see above.

To export MySQL port, I tried with the statement

docker run -d -P mysql:latest mysqldb

It does not work at all. What am I doing wrong?

migrated from stackoverflow.com Nov 25 '15 at 3:09

This question came from our site for professional and enthusiast programmers.

9

It looks like you ran the container without setting the -p 3306:3306 parameter. Also, it seems that you mistyped the IP address in of the Hostname in MySQL Workbench. I recommend starting from scratch by following these instructions:

  1. Run the mysql server. (Change the password admin to anything you want)

docker run -e MYSQL_ROOT_PASSWORD=admin --name mysql -d -p=3306:3306 mysql

  1. get the IP address of the default docker virtual machine by running

docker-machine ip default

  1. Copy the IP address that you'll get as the result of the previous command. (in your case, it should be 192.168.99.100)
  2. Open MySQL Workbench and create a new connection. Paste the IP address that you copied into the "Hostname" field.

You should be all set now.

1

The parameter -P binds the exported ports of a container automatically to available ports of the host.

The following command should bind the containers port 3306 to port 3306 of the host. See: Publish or expose port

docker run -d -p 3306:3306 mysql:latest mysqldb
  • I typed the statement docker run -d -p 3306:3306 mysql:5.7.9 dbmysql and as output I've got d38a0f208bcda50132d7f6f679c9282b0d90b275610b8d19ac93bf82d94eea43 but can still not access mysql container with mysql workbench. When I typed docker ps it shows me d6b44992ec77 mysql:5.7.9 "/entrypoint.sh mysql" About a minute ago Up About a minute 3306/tcp dbmysql – zero_coding Nov 25 '15 at 19:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.