简体   繁体   English

docker 容器 Mysql 端口外部访问问题

[英]docker container Mysql Port outside access issue

I've a mysql inside docker container, which is running on the server.我在 docker 容器内有一个 mysql,它在服务器上运行。 And I can run it normally inside the container using我可以使用它在容器内正常运行它

mysql -u root -h localhost --port=3306 -p

I've mapped the container 3306 to host 33069 port.我已将容器 3306 映射到主机 33069 端口。

netstat -tnlp | grep :33069

the above command runed on the server shows me the following result在服务器上运行的上述命令向我显示了以下结果

tcp6       0      0 :::33069                :::*                    LISTEN      120562/docker-proxy

from which it's clear that mysql is available not only for localhost .从中可以清楚地看出 mysql 不仅适用于localhost However when I try to connect to the mysql from my local machine using the command但是,当我尝试使用命令从本地计算机连接到 mysql 时

mysql -u root -h myAddress.com --port=33069 -p

I get the error Can't connect to MySQL server on... after timeout.我收到错误Can't connect to MySQL server on...超时后。 What I've missed?我错过了什么?

if you are using the docker run command, the container's port 3306:33069 needs to be exposed, and the docker MySql container host's server port, if the firewall is enabled for the port 33069.如果您使用的是 docker 运行命令,则需要暴露容器的端口 3306:33069,并且 docker MySql 为容器主机启用防火墙。如果端口 3 为端口 3

Afterwards on your local pc, the port 33069 needs to be open, to communicate to MySql docker container.之后在您的本地电脑上,需要打开端口 33069,以便与 MySql docker 容器通信。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM