Run a MySQL instance with docker

I wanted to use docker to run MySQL in isolation so i could change it’s version/state at anytime.  I see a special benefit when running MySQL or any application in a isolation where it does not depend around host machines file-system or Operating system, which means it allows us to run any available version instantly. Also they’re highly portable.

In this example I’ve used official docker-MySQL to run instances. Official image is flexible to configure around our specific needs and it’s been well documented.

Please refer to official docker-MySQL page for more configuration options.

 

Following Makefile allows to run persistent and non-persistent MySQL instances which opens up port 3306 on host machines to containerised MySQL instance. Current MySQL version  is 5.5 and default persistent directory been set. Feel free to change as required.

https://gist.github.com/KasunDon-awin/85c331de7f2f81579135530d51342764

Download above file and called it as mysql-server or any name you wanted. Then simply execute following commands in order to launch/stop/restart instances.

If you need persistent MySQL instance to be launched use

make -f mysql-server start-persistent

or use following for non-persistent instances

make -f mysql-server start

Stop or restarting instances can be done as below,
make -f mysql-server stop
make -f mysql-server restart

That’s all you can access your MySQL instance with your default mysql-client.

mysql -h 127.0.0.1 -u root

Leave a Reply

Your email address will not be published. Required fields are marked *