CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
255650e5e83d mariadb “docker-entrypoint…” 3 seconds ago Up 1 second 0.0.0.0:3306->3306/tcp festive_ride
查看启动占用的端口
root@debian1:~/nginx# netstat -tunl|grep 3306
tcp6 0 0 :::3306 :::* LISTEN
链接docker的mysql
root@debian1:~/nginx# mysql -uroot -phanye131 -h227.0.0.1 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 5.5.5-10.2.6-MariaDB-10.2.6+maria~jessie mariadb.org binary distributionCopyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.mysql>
错误解决方案
如果提示无法链接找到sock文件,你需要链接到docker的mariadb容器之内来授权链接
链接到docker mariadb之内
获取mariadb的CONTAINER ID
root@debian1:~/nginx# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
255650e5e83d mariadb “docker-entrypoint…” 10 minutes ago Up 10 minutes 0.0.0.0:3306->3306/tcp festive_ride 360baf71efb0 a3ae0b27ec04 “/run.sh bash” 3 hours ago Exited (2) 3 hours ago nginx
MariaDB [(none)]> grant all on . to ‘root’@’192.168.1.%’ identified by ‘hanye131’; Query OK, 0 rows affected (0.01 sec)