MySQL conf file in MySQL docker
Asked Answered
A

1

6

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/?

Angular answered 18/12, 2017 at 5:43 Comment(0)
S
8

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
Spumescent answered 18/12, 2017 at 6:4 Comment(8)
I tried removing /root/test/mysql/etc then start the Docker container using the command stated in the question. /root/test/mysql/etc gets created, but it is still empty... Am I doing something wrong?Angular
Also tried removing /root/test/mysql/etc, then started the Docker container using the same command, first without mounting /etc/mysql. Then I stopped and removed the Docker container and ran the command containing both -v arguments. /root/test/mysql/etc gets created now, but is still empty...Angular
My bad. The first option doesn't work. The directory is getting created empty and is getting mounted onto /etc/mysql which makes it empty. The only option is to create the volume and mount the named volume. This will give you the desired effect.Spumescent
Tried the second option. Running sudo docker volume create ... returned mysql_vol. Then I ran the second command sudo docker run .... However the folder /root/test/mysql/etc was not created...Angular
Just create it manually and keep it empty when using this optionSpumescent
Oops. Created the empty folder /root/test/mysql/etc, then ran the 2 commands, but the folder remains emptyAngular
This should work. Do it step by step. docker volume rm mysql_vol, delete /root/test/mysql/var/lib and the recreate it. Finally run the above commands in the question.Spumescent
Works now! Left out docker volume rm mysql_vol during previous retries.Angular

© 2022 - 2024 — McMap. All rights reserved.