Connect to mysql running on a docker container

I am trying to start a mysql server on a Docker container (installed with the Docker Toolbox for Mac) and access it from my machine running OS X Yosemite. The documentation from the official repo does not explain how to connect from outside the host docker!

I created a container with an official repository as follows:

$ docker pull mysql $ docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:latest $ docker inspect CONTAINER_ID 

Then I get the ip address (172.17.0.1), but when I ping it, I see timeouts !!! How can I connect to a running mysql server?

+5
source share
1 answer

It says:

This image provides the standard MySQL port (3306), so container binding makes the MySQL instance available to other application containers.

First, make sure your docker starts the card, that port: -p 3306:3306 (or the open port from the Docker file will not be accessible from the Linux host)

Then you need

After the discussion, it turned out that adding a port mapping to the end is wrong:

 docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:latest -p 3306:3306 

This does not work because "-p 3306: 3306" is simply interpreted as arguments to go to the ENTRYPOINT command.

This works (which means the docker ps -a shows the container how it "works" and not "exits"):

  docker run -p 3306:3306 --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:latest 

Then root@127.0.0.1 :3306 or root@ $(docker-machine ip):3306 should be correct.

+2
source

All Articles