挂载卷时Docker MySQL无法运行

时间:2019-03-10 10:15:54

标签: mysql docker

尝试使用存储在文件夹中的数据库数据运行mysql docker映像:

mkdir myfolder
sudo docker run --privileged --name my_mysql -e MYSQL_ROOT_PASSWORD=123 -v "$PWD/myfolder":/var/lib/mysql -d mysql

容器平整,日志显示以下信息:

sudo docker logs --tail=50 abcdef
Initializing database
mysqld: Can't create directory '/var/lib/mysql/' (OS errno 17 - File exists)
2019-03-10T10:03:42.872059Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2019-03-10T10:03:42.872191Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.15) initializing of server in progress as process 30
2019-03-10T10:03:42.875755Z 0 [ERROR] [MY-013236] [Server] Newly created data directory /var/lib/mysql/ is unusable. You can safely remove it.
2019-03-10T10:03:42.875824Z 0 [ERROR] [MY-010119] [Server] Aborting
2019-03-10T10:03:42.876931Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.15)  MySQL Community Server - GPL.

这是怎么回事?我之前在没有问题的其他数据库中完成过这类事情。

非常感谢!

1 个答案:

答案 0 :(得分:0)

根据此https://github.com/docker-library/mysql/issues/69,这是一个已知问题。 麻烦的解决方案是:

  1. 运行sudo docker run --privileged --name my_mysql -e MYSQL_ROOT_PASSWORD=123 -d mysql
  2. 将创建的_data文件夹中的volumes/volumeid/文件夹移动到本地目录(在我的情况下,将其重命名为myfolder
  3. 运行sudo docker run --privileged --name my_mysql -e MYSQL_ROOT_PASSWORD=123 -v "$PWD/myfolder":/var/lib/mysql -d mysql

:-/