mysql docker container not getting started,mysqld:无法创建/写入文件'/var/lib/mysql/is_writable'(操作系统错误13 -权限被拒绝)

2skhul33  于 2023-04-19  发布在  Mysql
关注(0)|答案(2)|浏览(538)

我已经创建了一个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机上执行上述方案.请帮助我为什么它的行为后,给予所有必要的权限卷和脚本文件夹这样.

bqf10yzr

bqf10yzr1#

问题似乎出在您的account文件夹。它可能已被使用或损坏。请创建一个新文件夹并进行测试。
删除合成文件中环境值的双引号。
如果要装载的主机上的文件夹不具有所需的写入权限:

  1. ssh到您的主机/节点
  2. chmod -R a+rwx /path/to/account/folder
fv2wmkja

fv2wmkja2#

同样的事情发生在我身上,为了快速解决问题,我做了:

sail down -v

如果你不使用sail,你可以:

docker-compose down -v

这个命令将删除你的容器和你的容器的卷,例如你的数据库,将被全部删除,但是对于那些处于开发模式并且只想做容器工作的人来说,这将有所帮助。
然后在你的项目中启动docker:

sail up -d

docker-compose up -d

相关问题