docker - docker-compose 问题:尝试创建/挂载卷时权限被拒绝
问题描述
我有以下 docker-compose.yml 文件:
version: "3"
services:
dbs-poa-loc001d:
image: percona
volumes:
- ./mysql_backup:/var/lib/mysql
- ./create_databases:/docker-entrypoint-initdb.d
hostname: "dbs-poa-loc001d"
container_name: dbs-poa-loc001d
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
ports:
- "3306:3306"
networks:
- azion-network
...
当我尝试创建 dbs-poa-loc001d 服务(项目的数据库)时,出现以下错误:
Starting dbs-poa-loc001d ... done
Attaching to dbs-poa-loc001d
dbs-poa-loc001d | Initializing database
dbs-poa-loc001d | mysqld: Can't create/write to file '/var/lib/mysql/is_writable' (Errcode: 13 - Permission denied)
dbs-poa-loc001d | 2019-01-11T01:17:52.060984Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
dbs-poa-loc001d | 2019-01-11T01:17:52.062286Z 0 [ERROR] --initialize specified but the data directory exists and is not writable. Aborting.
dbs-poa-loc001d | 2019-01-11T01:17:52.062299Z 0 [ERROR] Aborting
dbs-poa-loc001d |
dbs-poa-loc001d exited with code 1
在我工作的 MacOS 计算机上不会发生此错误,但在我的家用计算机(运行 Ubuntu 16.04)中会发生。我确实注意到mysql_backup
为保存卷数据而创建的主机上的文件夹设置为组和用户根。谁能告诉我发生了什么,我该如何解决?已经尝试但没有成功:
- 使用 sudo 运行 docker-compose 命令
- 手动将文件夹的所有者和用户更改为我的实际(低权限)用户。
我当前的设置和安装版本是:
- Ubuntu 16.04
- Docker 版本 18.09.0,构建 4d60db4
- docker-compose 版本 1.23.2,构建 1110ad0
- docker-compose 是使用安装的
sudo pip install docker-compose
解决方案
您可以尝试将权限设置mysql_backup
为 1001:0 吗?
类似sudo chown -R 1001:0 ./mysql_backup
或替代的东西,但前提是文件夹为空 sudo chmod 777 ./mysql_backup
关于 percona Dockerfile mysql 用户 id 是 1001 https://github.com/percona/percona-docker/blob/master/percona-server.80/Dockerfile
推荐阅读
- opentk - OpenTK 识别 PS4v2 控制器(通过 USB)
- machine-learning - 创建基于 3 列的预测模型
- android - IntentService 使用 NativeScript 和 Angular 处理 FCM
- r - ggplot2中的分组条形图
- qt - 仅从 Qt 中的给定 MIME 类型(无文件本身)获取文件图标
- c - C - 检查系统是否是虚拟机的便捷方法?
- javascript - 在循环中将不同的变量值传递给事件处理程序
- python - PLY - 添加第二条类似行时出现解析错误
- ssl - sslstrip2 + dns2proxy --> dnsalert
- angular - 如何在分配给 formControlName 的对象中添加附加属性