简体   繁体   中英

MySQL fail to start in Docker when mount /etc to host

I use below command to start MySQL container:

docker run --name mysql-for-teamcity \
-e MYSQL_ROOT_PASSWORD=FAKE-ROOT-PWD \
-v ~/MySQL/var_lib_mysql:/var/lib/mysql \
-v ~/MySQL/etc:/etc \
-p 3306:3306 \
-p 33060:33060 \
-it mysql

But MySQL won't start and complains:

ERROR: mysqld failed while attempting to check config
command was: "mysqld --verbose --help"

mysqld: Error on realpath() on '/var/lib/mysql-files' (Error 2 - No such file or directory)
2018-12-05T07:33:50.856816Z 0 [ERROR] [MY-010095] [Server] Failed to access directory for --secure-file-priv. Please make sure that directory exists and is accessible by MySQL Server. Supplied value : /var/lib/mysql-files
2018-12-05T07:33:50.859460Z 0 [ERROR] [MY-010119] [Server] Aborting

If I remove -v ~/MySQL/etc:/etc \\ then MySQL would start correctlly.

Why can't I mount /etc to my host in Docker?

This is my silly mistake; it should be an RTFM question.

According to Docker manual , Bind mounts are used to bind directory into a container, not out .

So when I specified -v ~/MySQL/etc:/etc , the contents in my "~/MySQL/etc" would obscure the original contents in "/etc" of the MySQL image.

That's why mysqld failed while attempting to check config. Because the config does not exist in my "~/MySQL/etc/".

I leave the answer here in case someone else does not read the manual:(

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM