docker无法通过宿主ip访问容器中的mysql
过去多啦不再A梦
过去多啦不再A梦 2017-04-25 09:01:33
0
7
1578

如图

这里设置的应该是,将容器的3306映射到主机的3366上,但是我只能通过192.168.99.100:3366来连接容器内的mysql服务

我宿主机的真实ip是10.0.0.2

但是我通过10.0.0.2:3366却连接不上,求大神指点一下

过去多啦不再A梦
过去多啦不再A梦

reply all (7)
習慣沉默

To answer your question directly:
The reason why you have to go through a192.168.99.100:3366来访问容器而不是宿主机的IP:10.0.0.2,就在于:你用了Toolbox, 而Toolbox默认用到了Virtualboxvirtual 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.

    我想大声告诉你

    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:

        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

          PHPzhong

          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.

                Latest Downloads
                More>
                Web Effects
                Website Source Code
                Website Materials
                Front End Template
                About us Disclaimer Sitemap
                php.cn:Public welfare online PHP training,Help PHP learners grow quickly!