我创建了一个docker compose文件来运行mysql docker容器并使用数据库脚本初始化数据库。
启动容器时,出现以下错误。
account-service-db_1 | Initializing database
account-service-db_1 | mysqld: Can't create/write to file '/var/lib/mysql/is_writable' (OS errno 13 - Permission denied)
account-service-db_1 | 2019-05-11T16:58:35.265463Z 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.
account-service-db_1 | 2019-05-11T16:58:35.265550Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.16) initializing of server in progress as process 15
account-service-db_1 | 2019-05-11T16:58:35.268464Z 0 [ERROR] [MY-010460] [Server] --initialize specified but the data directory exists and is not writable. Aborting.
account-service-db_1 | 2019-05-11T16:58:35.268472Z 0 [ERROR] [MY-013236] [Server] Newly created data directory /var/lib/mysql/ is unusable. You can safely remove it.
account-service-db_1 | 2019-05-11T16:58:35.269284Z 0 [ERROR] [MY-010119] [Server] Aborting
account-service-db_1 | 2019-05-11T16:58:35.270510Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.16) MySQL Community Server - GPL.
docker-swarm-account-service-mysql-demo_account-service-db_1 exited with code 1
经过研究,许多人建议在撰写文件中添加用户:“ 1000:50”将解决该问题。但是在添加后,我也遇到相同的错误。
请在下面找到我的docker-compose文件
version: '3.7'
services:
account-service-db:
user: "1000:50"
image: mysql
environment:
- MYSQL_DATABASE=account-service
- MYSQL_USER=mysqluser
- MYSQL_PASSWORD=mysqlpassword
- MYSQL_ROOT_PASSWORD=mysqlpassword
volumes:
- "/Users/admin/dockerfiles/docker-swarm-account-service-mysql-demo/scripts/:/docker-entrypoint-initdb.d/"
- "/Users/admin/dockerfiles/docker-swarm-account-service-mysql-demo/account:/var/lib/mysql"
ports:
- "3306:3306"
deploy:
replicas: 1
placement:
constraints:
- node.labels.mysql.node == true
restart_policy:
condition: on-failure
delay: 10s
#max-attempts: 3
我正在Mac机器上执行上述方案。给卷和脚本文件夹提供所有必要的权限后,请帮助我为什么它会如此显示。
答案 0 :(得分:1)
问题似乎出在您的account
文件夹中。它可能已经在使用中或已损坏。创建一个新文件夹并进行测试。
从撰写文件的环境值中删除双引号。
如果正在安装的主机上的文件夹没有所需的写权限:
chmod -R a+rwx /path/to/account/folder