Docker安裝MYSQL無法運行的天坑 mysqld: Can't read dir of '/etc/mysql/conf.d/' (OS errno 13 - Permission den...

機器環(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 buildroot os. However docker driver's vm os is ubuntu.
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 profile

If 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ù),只運行容器。

歡迎補充最新的解決方案。??

參考:

docker部署mysql出錯:mysqld: Can't read dir of '/etc/mysql/conf.d/' (Errcode: 13 - Permission denied)_Kingtu_linux的博客-CSDN博客

Mysql, Privileged mode, cannot open shared object file · Issue #7512 · moby/moby (github.com)

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容