1、进入容器
docker exec -it mysql /bin/bash
echo "[mysqld]
datadir=/var/lib/mysql
socket=/var/run/mysqld/mysqld.sock
skip-grant-tables" >> /etc/mysql/mysql.conf.d/mysqld.cnf
2、退出容器,重启mysql
docker restart mysql
3、进入容器,修改密码
docker exec -it mysql /bin/bash
mysql -u root
use mysql
UPDATE user SET authentication_string=PASSWORD('your_password_修改') WHERE User='root';
exit
[重要!删除配置文件!]
rm -rf /etc/mysql/mysql.conf.d/mysqld.cnf
exit
4、重启mysql
docker restart mysql