This post shows us how we connect to MySQL container from the host OS. I am using Mac OS and running vagrant. In vagrant box, I have a MySQL container running so I will connect to it from Mac OS.


MySQL container


Run commands below while you are in vagrant box so that we get the IP address of the container.


$ docker-compose ps
Name Command State Ports
----------------------------------------------------------------------------
app_mysql_1 docker-entrypoint.sh mysqld Up 0.0.0.0:3306->3306/tcp

$ echo $(docker inspect app_mysql_1 | grep IPAddress | grep -o -E '[0-9\.]+')
172.18.0.2

Sequel Pro


Create a new SSH connection and use values below. That's it!


MySQL Host: 172.18.0.2
Username: root
Password: root
SSH Host: 192.168.99.30 # Vagrant IP
SSH User: vagrant # Vagrant user
SSH Key: .vagrant/machines/machine/virtualbox/private_key # Vagrant box's key