MySQL with Docker

First, I pulled the image ‘docker pull mysql’ that was the last easy thing I did.

I wanted to use my own my.cnf file. So put it in /my/custom and used:

‘-v /my/custom:/etc/mysql’.

I pulled a highly optimized one off github:

https://gist.githubusercontent.com/rhtyd/d59078be4dc88123104e/raw/12d79310970e21604480c41d0c34813e6946be44/my.cnf

I had to comment a lot out as many options are deprecated

#datadir   = /var/lib/mysql
#lc-messages-dir         = /usr/share/mysql
#thread_concurrency      = 8 # Max CPU * 2
# MyISAM
#key-buffer-size         = 32M
#myisam-recover          = FORCE,BACKUP
#myisam_sort_buffer_size = 64M
# CACHES AND LIMITS #
#query-cache-type        = 0
#query-cache-size        = 0
#query_cache_limit       = 1M
# Bin logs
#expire-logs-days        = 5
#innodb_additional_mem_pool_size = 20M
#innodb_locks_unsafe_for_binlog  = 1
#log-error                       = /var/log/mysql/mysql-error.log
#!includedir /etc/mysql/conf.d/.

Next, I had to copy the DB tables. For this I tarred them up from the docker image and ftped them to the docker host. Once I expanded them, I used:

‘-v /my/own/datadir:/var/lib/mysql’.

Then came the really tough part. I kept getting this error about ‘mysql-files’ so I found this Chinese website and used Google Translate

https://translate.google.com/translate?hl=en&sl=zh-CN&u=https://www.cnblogs.com/s1956/p/9997691.html&prev=search

making the final piece:

‘-v /my/mysql-files:/var/lib/mysql-files’.

So the full command to launch the container with a custom config and an external, persistent database was:

‘docker run -p 3306:3306 –name mysql -v /my/custom:/etc/mysql -v /my/own/datadir:/var/lib/mysql -v /my/mysql-files:/var/lib/mysql-files -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql’.

I was able to use mysql-workbench over the network and connect to the container.