Connecting in to Docker MySQL Instance

Just recording a few of these steps for future reference.

Pull the MySQL image from the hub:

docker pull mysql/mysql-server:latest

Run an instance:

docker run -it -d -p 33060:3306 --name mysql-for-jonny -e MYSQL_ROOT_PASSWORD=opensesame -d mysql/mysql-server:latest

Run a shell on the instance:

docker exec -it mysql-for-jonny /bin/bash

Once inside the instance use the MySQL client:

mysql -u root -popensesame

and create a new user:

GRANT ALL PRIVILEGES ON *.* TO jonny@'%' IDENTIFIED BY 'letjonnyin';

Quit the MySQL client and exit the instance. From the host system try connecting to MySQL on the instance:

mysql -u jonny -pletjonnyin -h localhost --protocol=tcp --port 33060

Now that instance of MySQL can be inspected from the host.

Leave a Reply

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>