Home  >  Q&A  >  body text

docker无法通过宿主ip访问容器中的mysql

如图

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

我宿主机的真实ip是10.0.0.2

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

过去多啦不再A梦过去多啦不再A梦2757 days ago1626

reply all(7)I'll reply

  • 習慣沉默

    習慣沉默2017-04-25 09:03:33

    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.

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-04-25 09:03:33

    Try turning off the firewall

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-04-25 09:03:33

    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.

    reply
    0
  • 怪我咯

    怪我咯2017-04-25 09:03:33

    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

    reply
    0
  • PHPz

    PHPz2017-04-25 09:03:33

    To add the network segment of the docker container to the firewall, please allow access to the host

    reply
    0
  • PHP中文网

    PHP中文网2017-04-25 09:03:33

    iptables -F

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-04-25 09:03:33

    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.

    reply
    0
  • Cancelreply