如圖
這里設(shè)置的應(yīng)該是,將容器的3306映射到主機的3366上,但是我只能通過192.168.99.100:3366來連接容器內(nèi)的mysql服務(wù)
我宿主機的真實ip是10.0.0.2
但是我通過10.0.0.2:3366卻連接不上,求大神指點一下
To answer your question directly:
The reason why you have to go through a 192.168.99.100:3366
來訪問容器而不是宿主機的IP:10.0.0.2
,就在于:你用了 Toolbox
, 而 Toolbox
默認(rèn)用到了 Virtualbox
virtual machine is that there is an extra layer.
Picture description:
@Youming is right. It is recommended that you use Docker for Mac. Toolbox
It will be gradually abandoned.
Try to see if you can connect to it in the container. By default, mysql configuration can only connect to the IP address of 127.0.0.1.
Provide some ideas:
First test the service status of mysql service on each IP through port 3306, such as:
telnet 10.0.0.2 3306
telnet 192.168.99.100 3306
If telnet finds that the port is open, then check the setting problem of mysql, that is, whether mysql clients with other IP addresses are allowed to access
To add the network segment of the docker container to the firewall, please allow access to the host
Why are you using the Toolbox version of Docker now? If you directly use the latest version of Docker for Mac, your problem will not be a problem...
Docker actually runs in a Linux virtual machine on a Mac system. The Toolbox version of Docker uses VirtualBox as a virtual machine. Because it is a third-party application and the interface provided by the application is limited, although Docker can map ports to virtual on the machine, but the port of the virtual machine cannot be mapped to the host. To achieve this mapping, you need to manually do port mapping in VirtualBox.
The new version of Docker for Mac uses xhyve as the virtual machine provider. Due to the native support of the Mac system, it provides a richer interface. Docker for Mac can also automatically complete the port mapping between the virtual machine and the host. Therefore, in the new version of Docker for Mac, there is no need to manually map the virtual machine to the host port. You can directly use the local port 127.0.0.1 to access the container bound to it.