CentOS下啓動docker和docker啓動MySQL鏡像後無法連接MySQL

1.CentOS下啓動docker失敗

  1.1安裝docker後啓動失敗並出現以下信息:  

Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.

  1.2查看失敗後的原因,好像是由於docker不支持圖像內核驅動:SELinux不支持這個內核上的OrthALA2圖形驅動程序。

  1.3重新編輯docker配置文件:vi /etc/sysconfig/docker  

# /etc/sysconfig/docker

# Modify these options if you want to change the way the docker daemon runs
OPTIONS=‘--selinux-enabled=false --log-driver=journald --signature-verification=false‘
if [ -z "${DOCKER_CERT_PATH}" ]; then
    DOCKER_CERT_PATH=/etc/docker
fi

  重新啓動即可成功。主要是在--selinux-enabled後加上“=false”。

2.連接超時,pull不到遠程的鏡像。解決方法是使用國內的鏡像源,速度穩定且更快。

  2.1更換系統中默認的鏡像源:vi /etc/sysconfig/docker    更改配置後重啓服務。

OPTIONS=' --selinux-enabled  --log-driver=journald --registry-mirror=http://f2d6cb40.m.daocloud.io'

  2.2在pull時在命令裏配置新的數據源,推薦第一種。

3.啓動MySQL鏡像後產生容器,遠程連接容器出現 Authentication plugin 'caching_sha2_password' cannot be loaded 的錯誤。

    3.1常見的解答  

ALTER USER 'username'@'ip_address' IDENTIFIED WITH mysql_native_password BY 'password';

OR

We can avoid this error by make it work with old password plugin:

First change the authentication plugin in my.cnf file for Linux / my.ini file in Windows:

[mysqld]

default_authentication_plugin=mysql_native_password

Restart the mysql server to take the changes in affect and try connecting via MySQL with any mysql client.

If still unable to connect and getting the below error:

Unable to load plugin 'caching_sha2_password'
It means your user needs the above plugin. So try creating new user with create user or grant command after changing default plugin. then new user need the native plugin and you will able to connect MySQL.

  3.2或者設置密碼爲空  

docker run -p 3306:3306 -e MYSQL_ALLOW_EMPTY_PASSWORD=yes -d mysql --default-authentication-plugin=mysql_native_password
mysql -uroot --protocol tcp

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章