环境
docker Version: 18.06.3-ce
mysql 5.7
问题描述:
新创建mysql容器,重启错误Could not open file ‘/var/log/mysqld.log’ for error logging: Permission denied
查看日志报错
[root@localhost srv]# docker logs -f 848a2581da80
2022-04-01 06:39:23+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.37-1debian10 started.
2022-04-01 06:39:23+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2022-04-01 06:39:23+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.37-1debian10 started.
2022-04-01 06:39:23+00:00 [Note] [Entrypoint]: Initializing database files
2022-04-01T06:39:23.954124Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-04-01T06:39:23.955246Z 0 [ERROR] Could not open file '/var/log/mysqld.log' for error logging: Permission denied
2022-04-01T06:39:23.955259Z 0 [ERROR] Aborting
解决方案:
1.修改之前创建文件夹权限
[root@localhost srv]# ll
总用量 0
drwxr-xr-x 2 root root 20 4月 1 14:12 conf
drwxr-xr-x 2 polkitd root 6 4月 1 14:39 data
drwxr-xr-x 2 root root 6 4月 1 11:13 logs
[root@localhost srv]# chmod 777 logs
[root@localhost srv]# ll
总用量 0
drwxr-xr-x 2 root root 20 4月 1 14:12 conf
drwxr-xr-x 2 polkitd root 6 4月 1 14:39 data
drwxrwxrwx 2 root root 6 4月 1 11:13 logs
[root@localhost srv]# chmod 777 conf
[root@localhost srv]# chmod 777 data
[root@localhost srv]# ll
总用量 0
drwxrwxrwx 2 root root 20 4月 1 14:12 conf
drwxrwxrwx 2 polkitd root 6 4月 1 14:39 data
drwxrwxrwx 2 root root 6 4月 1 11:13 logs
2.重启容器
[root@localhost srv]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
848a2581da80 mysql:5.7 "docker-entrypoint.s…" 7 minutes ago Exited (1) 7 minutes ago mysql
[root@localhost srv]# docker start 848a2581da80
848a2581da80
[root@localhost srv]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
848a2581da80 mysql:5.7 "docker-entrypoint.s…" 7 minutes ago Up 3 seconds 33060/tcp, 0.0.0.0:3307->3306/tcp mysql