Connect to MySQL in Docker Container

If you like to connect to the MySQL Database inside the Docker container with an external Tool like Sequel Pro, MySQL Workbench, HeidiSQL, DBeaver, just plain old mysql cli or anything else.

Get published mysql port from container

Docker assigns a randomly published port for MySQL during each container start. This is done to prevent port collisions.

To get the published port via docker:

$ docker port
3306/tcp ->

Or via docker-compose inside a Drupal repository

$ docker-compose port drupal 3306

linux Get ip from container

If you are on Linux and run docker natively, you also need to get the IP of the container

$ docker inspect --format '{{ .NetworkSettings.IPAddress }}'

Connect to MySQL

Linux OS X
IP/Host ip from container
Port published port from container published port from container
Username drupal drupal
Password drupal drupal
Database drupal drupal

Example Sequel PRO

Screenshot SequelPro