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 默认用到了 Virtualbox virtual machine is that there is an extra layer.
Picture description:
@Youming is right. It is recommended that you use Docker for Mac. ToolboxIt will be gradually abandoned.
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
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.
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
默认用到了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 turning off the firewall
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:
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
iptables -F
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.