Docker mysql [Warning] World-writable config file '.cnf' is is ignored

这其实是 Docker 在 Windows 下的坑! 理论上 Docker for Mac 也会遇到同样的问题。

零、问题描述

近期都在 Docker Compose 部署项目,在服务器上好好的,但到了我本地的 Windows 开发机上,Mysql 的字符集设置一直不生效,醉了。

./docker-compose.yml 内容:

version: "2"
services:
  mysql:
    build: ./builds/mysql
    ports:
      - "3386:3306"
    volumes:
      - "./data/mysql/data:/var/lib/mysql"
      - "./data/mysql/conf:/etc/mysql/conf.d"
    restart: always
    environment:
      MYSQL_DATABASE: blua
      MYSQL_USER: blua
      MYSQL_PASSWORD: blua
      MYSQL_ROOT_PASSWORD: blua
  # orrder service so no...

我的./data/mysql/conf/mysql.cnf 内容:

[client]
default-character-set=utf8mb4

[mysql]
default-character-set=utf8mb4

我的./data/mysql/conf/docker.cnf 内容:

[mysqld]
skip-host-cache
skip-name-resolve

character-set-client-handshake=FALSE
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'

lower_case_table_names=1

max_allowed_packet=128M
innodb_log_file_size=256M

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

然后查看 mysql 这个 service 的日志:

# docker-compose logs mysql

发现了两句警告:

mysql: [Warning] World-writable config file '/etc/mysql/conf.d/docker.cnf' is ignored
mysql: [Warning] World-writable config file '/etc/mysql/conf.d/docker.cnf' is ignored

然后再进去查看这两个配置文件的权限信息:

# docker-compose exec mysql bash
# ls -l /etc/mysql/conf.d/
-rwxrwxrwx 1 root root 309 Jun 20 16:47 docker.cnf
-rwxrwxrwx 1 root root  78 Jun 20 16:47 mysql.cnf

Mysql 的配置文件因为读写权限不安全(竟然是完全的读-写-执行权限)被 Mysql 的安全机制忽了,进而导致我的字符集设置没生效。

Linux 下不会出现这种问题,我的 Windows8.1 用的是 DockerToolBox,不太确定 Docker for WindowsDocker for Mac 会不会出现这种问题。

Google 一下,发现也有很多类似的问题:docker-compose volumes 777

但是我不太想深究了。。反正都是 Windows 的锅。。应该还是有解决方案的,或者深究的话还可以了解下 volumns 的挂载和权限机制。。

一、解决方案

第一种讨论:在 DockerFile 里做这一步的文件复制,并且修改文件权限:Fixing World-writable MySql error in Docker

第二种讨论:修改 docker-machine VM 默认的挂载的权限?MySQL in Docker on Windows: World-writable files ignored

第三种:最简单的方案,把你的项目,放到你的用户目录下!Docker Engine 会自动挂载用户目录 C:\Users (Windows) or /Users (Mac)。项目放在用户目录(或子目录)下就会被挂载进 Docker Engine,此时就不会再出现共享进去的文件的权限被变成 root 用户的 -rwxrwxrwx 文件了!Docker Compose Get started 里的 Shared folders, volumes, and bind mounts 也有提及这一点。

第三种应该就是最好的方案了,以前项目都放 D 盘,现在要用 Docker 跑的都放 C 盘的用户目录下了,真是专治各种不服。

附、参考资料

  • 5
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 8
    评论
As an AI language model, I don't have access to the content of the file './docker/docker-compose-test-net.yaml'. However, here are some common reasons that a Docker Compose file may be invalid: 1. Syntax errors: The file may contain syntax errors such as missing brackets, commas, or quotation marks. 2. Incorrect indentation: The indentation of the file may be incorrect, causing errors in the parsing of the file. 3. Incorrect version number: The version number of the file may be incorrect, causing the file to be invalid. 4. Invalid or misspelled service names: The names of the services defined in the file may be misspelled or invalid. 5. Invalid or missing network configuration: The network configuration in the file may be invalid or missing, causing errors in the creation of the network. 6. Invalid or missing environment variables: Environment variables defined in the file may be invalid or missing, causing errors in the execution of the services. 7. Invalid volumes or mounts: The volumes or mounts defined in the file may be invalid, causing errors in the mounting of the directories or files. 8. Invalid or missing dependencies: The dependencies defined in the file may be invalid or missing, causing errors in the execution of the services. 9. Incorrect or missing container configurations: The configurations of the containers defined in the file may be incorrect or missing, causing errors in the creation or execution of the containers. 10. Invalid or missing health checks: The health checks defined in the file may be invalid or missing, causing errors in the monitoring of the containers.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值