Caleb Caleb - 1 year ago 365
MySQL Question

Connect to Docker MySQL container from localhost?

I have a docker mysql image running, following is what the docker-compose.yml file looks like:

image: mysql
- "3306:3306"

This works fine.

My question is: How can I connect to the MySQL instance running on that container from the command line mysql client on my the host (my macbook)?

To clarify:

  • I have a macbook with Docker installed

  • I have a docker container with mysql

  • I want to connect to the mysql instance running on the aforementioned container from the Terminal on my macbook

  • I do NOT want to user a
    command to make this possible. Rather, I want to use the
    client directly from the Terminal (without tunneling in through a docker container).

I don't have MySQL running locally, so port 3306 should be open and ready to use.

The command I am using to start the container is:
docker-compose run

Answer Source

I got it!! The answer is to use the --service-ports option when running docker-compose:

docker-compose run --service-ports db (the original docker-compose.yml file works fine)

Thanks to all for the help!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download