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

猜你喜欢

转载自blog.csdn.net/qq_32801733/article/details/81220129