我使用以下命令启动MySQL容器:
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
但是MySQL无法启动并抱怨:
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
如果我删除-v ~/MySQL/etc:/etc \
,则MySQL将正确启动。
为什么不能在Docker中将/ etc挂载到主机上?
答案 0 :(得分:1)
这是我愚蠢的错误;应该是一个RTFM问题。
根据Docker manual,绑定安装用于将目录绑定到到容器中,而不是输出。
因此,当我指定-v ~/MySQL/etc:/etc
时,“〜/ MySQL / etc”中的内容将掩盖MySQL映像“ / etc”中的原始内容。
这就是为什么mysqld在尝试检查配置时失败。因为该配置在我的“〜/ MySQL / etc /”中不存在。
如果有人不读本手册,我会在这里留下答案:(