機器環(huán)境:VM虛擬機安裝的Centos 7虛擬機,docker 1.13.1,測試了mysql 5.7和最新版(2022年1月17日)。
這兩天使用Docker部署Mysql遇到MYSQL無法啟動,使用的命令如下:
sudo docker run -p 3308:3306 -v /home/noel/mysql/conf:/etc/mysql/conf.d -v /home/noel/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 --name mysql -d mysql --privileged=true
查看日志,顯示如下內(nèi)容:
2022-01-17 07:20:03+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
2022-01-17 07:20:03+00:00 [ERROR] [Entrypoint]: mysqld failed while attempting to check config
command was: mysqld --privileged=true --verbose --help --log-bin-index=/tmp/tmp.eNqBDydbME
mysqld: Can't read dir of '/etc/mysql/conf.d/' (OS errno 13 - Permission denied)
mysqld: [ERROR] Stopped processing the 'includedir' directive in file /etc/mysql/my.cnf at line 29.
mysqld: [ERROR] Fatal error in defaults handling. Program aborted!
日志提示是沒有讀權(quán)限訪問容器內(nèi)MySQL的目錄,網(wǎng)上查詢到的是Ubuntu這類有apparmor訪問控制的策略的系統(tǒng),與容器MySQL的安全策略沖突,git issues 也只看到大神們是測試通過,沒有徹底的解決方案:
AppArmor is ubuntu specific security.
If os is Ubuntu and docker is used, this error will happen.Minikube's vm use
buildrootos. However docker driver's vm os isubuntu.
So I think this is why the docker_ubuntu test failed.It may had better add document for specific user who wants to runs mysql on minikube with docker driver on Ubuntu machine.
minikube網(wǎng)站給出提示:
Deploying MySql on a linux with AppArmor
On Linux, if you want to run MySQL pod, you need to disable AppArmor for mysql profileIf your docker has AppArmor enabled, running mysql in privileged mode with docker driver will have the issue #7401. There is a workaround - see moby/moby#7512.
最后,在Ubuntu系統(tǒng)開發(fā)測試機上,網(wǎng)友給出如下解決方案:
sudo ln -s /etc/apparmor.d/usr.sbin.mysqld /etc/apparmor.d/disable/
sudo apparmor_parser -R /etc/apparmor.d/usr.sbin.mysqld
在Centos環(huán)境下(實際上發(fā)布環(huán)境,系統(tǒng)也不會同時出現(xiàn)Mysql服務(wù)和Mysql容器吧?),刪除Mysql服務(wù),只運行容器。
歡迎補充最新的解決方案。??
參考:
Mysql, Privileged mode, cannot open shared object file · Issue #7512 · moby/moby (github.com)