我从Dockerhub中提取了MySQL容器,它正在我的macbook pro上运行,如下所示
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
12cd3deaa3f0 mysql:latest "/entrypoint.sh mysql" 47 hours ago Up 10 minutes 3306/tcp mysqldb
然后,我下载了MySQL工作台,并尝试将其与MySQL容器连接,但是它不起作用。显示连接错误。
Your connection attempt failed for user 'root' from your host to server at 192.168.99.102:3306:
Can't connect to MySQL server on '192.168.99.102' (60)
来自docker机器的IP是
docker-machine ip default
192.168.99.100
如上所示,MySQL的端口为3306。
要导出MySQL端口,我尝试使用以下语句
docker run -d -P mysql:latest mysqldb
它根本不起作用。我究竟做错了什么?
docker run -d -p 3306:3306 mysql:5.7.9 dbmysql
并获得了输出,d38a0f208bcda50132d7f6f679c9282b0d90b275610b8d19ac93bf82d94eea43
但仍然无法使用mysql workbench访问mysql容器。当我键入d6b44992ec77 mysql:5.7.9 "/entrypoint.sh mysql" About a minute ago Up About a minute 3306/tcp dbmysql