mysql - How do I set the perms of a my.cnf file to be readonly from within Docker (not at the client's OS level)?
问题描述
I'm using docker-compose v 1.27 and Docker v 19.03. I have this in my docker-compose.yml file ...
version: '3'
services:
mysql:
restart: always
image: mysql:8.0
cap_add:
- SYS_NICE # CAP_SYS_NICE
environment:
MYSQL_DATABASE: 'directory_data'
# So you don't have to use root, but you can if you like
MYSQL_USER: 'root'
# You can use whatever password you like
MYSQL_PASSWORD: 'password'
# Password for root access
MYSQL_ROOT_PASSWORD: 'password'
MYSQL_ROOT_HOST: '%'
ports:
- "3406:3306"
volumes:
- my-db:/var/lib/mysql
- ./mysql/mysqlconf:/etc/mysql/conf.d
command: ['mysqld', '--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci']
Note that I have no Dockerfile (didn't think I needed it). My "my.cnf" file, is below
davea$ cat mysql/mysqlconf/my.cnf
bind-address = 0.0.0.0
From Docker, how do I set the permissions of the my.cnf file to be read-only? This comes into play on Windows 10 in which running "docker-compose up" results in this warning
mysqld: [Warning] World-writable config file '/etc/mysql/conf.d/my.cnf' is ignored.
Note, this answer -- https://stackoverflow.com/questions/64327260/in-docker-compose-how-do-i-set-perms-on-a-my-cnf-file-if-i-dont-have-a-dockerf, doesn't cut it, because it relies on setting th
解决方案
我认为这里的根本问题是您在 ext 文件系统中安装了 NTFS 目录卷。以下是一些可能有用的解决方案。
Docker 级别:使用只读卷挂载
您可以使用只读卷挂载而不是默认的读写设置。
例如,:ro
在卷规范的末尾添加(只读):
volumes:
- ...
- ./mysql/mysqlconf:/etc/mysql/conf.d:ro
容器级:chmod
配置文件
command
如果要抑制警告,可以尝试通过将配置扩展为多个命令,将运行时文件的权限设置为只读。不过,我认为这就是您所说的客户端操作系统级别。挂载不会是只读的。
例如:
command: bash -c "
chmod -R 0444 /etc/mysql/conf.d/ &&
mysqld --user=root --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
"
请注意,这与只读挂载不兼容,因为它是只读文件系统,因此您无法调整权限。
推荐阅读
- dialogflow-es - 在对话流中使用基本卡片调用意图而不使用 webhook
- artificial-intelligence - 为什么我的 VGG-19 实施效果不佳?
- python - 数组(['<=50K','>50K'],dtype=object)没有运行
- oracle - 谁能告诉,集合中的 OBJECT TYPE 是什么?
- c-preprocessor - 自定义条件预处理器指令
- java - 尝试从其他类访问 ArrayList 时出现 NullPointerException
- flutter - 如何在 Flutter 中固定卡片宽度?
- vue.js - 迭代Vue子组件中的字符串列表
- python - 如何在 django 数据迁移中更改站点模型对象?
- woocommerce - 导入和使用 WooCommerce API 后出现空白屏幕