我在我的localhost上运行了mysql
我可以通过运行来连接它:
MysqL -h 127.0.0.1 -P 3306 -u root -p
我还用命令运行了docker container:
docker run -tid -v $(pwd):/code -p 3306:3306 -p 5000:5000 --name container container
我想从docker容器访问我的MysqL数据库.所以我也从docker容器中输入:
MysqL -h 127.0.0.1 -P 3306 -u root -p
但它给了我错误:
ERROR 2003 (HY000): Can't connect to MysqL server on '127.0.0.1' (111)
我究竟做错了什么?端口似乎是正确的.
编辑1
在docker中输出ifconfig:
eth0 Link encap:Ethernet HWaddr 02:42:ac:11:00:02
inet addr:172.17.0.2 Bcast:0.0.0.0 Mask:255.255.0.0
inet6 addr: fe80::42:acff:fe11:2/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1780 errors:0 dropped:0 overruns:0 frame:0
TX packets:977 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2225781 (2.2 MB) TX bytes:56572 (56.5 KB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:28 errors:0 dropped:0 overruns:0 frame:0
TX packets:28 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:1400 (1.4 KB) TX bytes:1400 (1.4 KB)
最佳答案
原文链接:https://www.f2er.com/docker/436921.html