MySQL conf file in MySQL docker

Nyxynyx picture Nyxynyx · Dec 18, 2017 · Viewed 10.2k times · Source

I am running MySQL 5.7.20 in a docker container created using the official MySQL docker image. The MySQL conf file needs to be mounted on the host Ubuntu system.

Currently the MySQL docker container is started using the command

sudo docker run -d \
-p 3306:3306 \
-e MYSQL_ROOT_PASSWORD=test \
-v /root/test/mysql/var/lib:/var/lib/mysql \
-v /root/test/mysql/etc:/etc/mysql \
--name test-mysql \
mysql:5.7

However there are no conf files in /root/test/mysql/etc... Connected to the docker container's bash and found that /etc/mysql is empty!

Where are the conf files located? Shouldnt there be some in /etc/mysql/conf.d/ and /etc/mysql/mysql.conf.d/?

Answer

yamenk picture yamenk · Dec 18, 2017

If you run the command without mounting any volumes:

$ docker run -it mysql ls /etc/mysql
conf.d  my.cnf  my.cnf.fallback  mysql.cnf  mysql.conf.d

If /root/test/mysql/etc exists as an empty folder and you mount it onto /etc/mysql all the content of /etc/mysql will be "replaced" with those in /root/test/mysql/etc.

You can have an empty /root/test/mysql/etc folder and do the following:

docker volume create --driver local \
    --opt type=none \
    --opt device=/root/test/mysql/etc \
    --opt o=bind \
    mysql_vol

sudo docker run -d \
-p 3306:3306 \
-e MYSQL_ROOT_PASSWORD=test \
-v /root/test/mysql/var/lib:/var/lib/mysql \
-v mysql_vol:/etc/mysql \
--name test-mysql \
mysql:5.7