WindowsやMacOSで使うDocker Desktop
とはパーミッション周りの挙動が少し違うみたいです。
my.cnf
でログ出力設定をした際にエラーが出ました。
動くdocker-compose.yml
version: "3.7"
services:
mysql:
image: mysql:8
volumes:
- db_data:/var/lib/mysql
- type: bind
source: "./my.cnf"
target: "/etc/mysql/conf.d/my.cnf"
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
TZ: ${TZ:-UTC}
command: >
bash -c "mkdir -p /var/log/mysql
&& chown -hR mysql:mysql /var/log/mysql
&& /entrypoint.sh mysqld"
ports:
- ${MYSQL_PORT:-3306}:3306
restart: unless-stopped
volumes:
db_data:
※ command
の3行はインデントがずれると動かない場合があるので注意
追記部分
+ command: >
+ bash -c "mkdir -p /var/log/mysql
+ && chown -hR mysql:mysql /var/log/mysql
+ && /entrypoint.sh mysqld"
エラーと対処
No such file or directory
mysql_1 | 2022-06-30 01:50:51+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.29-1debian10 started.
mysql_1 | 2022-06-30 01:50:51+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
mysql_1 | 2022-06-30 01:50:51+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.29-1debian10 started.
mysql_1 | 2022-06-30 01:50:51+00:00 [Note] [Entrypoint]: Initializing database files
mysql_1 | 2022-06-30T01:50:51.803532Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.29) initializing of server in progress as process 41
mysql_1 | 2022-06-30T01:50:51.805709Z 0 [ERROR] [MY-010187] [Server] Could not open file '/var/log/mysql/error.log' for error logging: No such file or directory
mysql_1 | 2022-06-30T01:50:51.805753Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
mysql_1 | 2022-06-30T01:50:51.805762Z 0 [ERROR] [MY-010119] [Server] Aborting
→ ディレクトリ作成
mkdir -p /var/log/mysql
Permission denied
mysql_1 | 2022-06-30 01:56:49+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.29-1debian10 started.
mysql_1 | 2022-06-30 01:56:49+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
mysql_1 | 2022-06-30 01:56:49+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.29-1debian10 started.
mysql_1 | 2022-06-30 01:56:49+00:00 [Note] [Entrypoint]: Initializing database files
mysql_1 | 2022-06-30T01:56:49.795239Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.29) initializing of server in progress as process 44
mysql_1 | 2022-06-30T01:56:49.796978Z 0 [ERROR] [MY-010187] [Server] Could not open file '/var/log/mysql/error.log' for error logging: Permission denied
mysql_1 | 2022-06-30T01:56:49.797012Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
mysql_1 | 2022-06-30T01:56:49.797019Z 0 [ERROR] [MY-010119] [Server] Aborting
→ パーミッション設定
chown -hR mysql:mysql /var/log/mysql