无法远程连接到dockerized的mysql db [英] Unable to connect to dockerized mysql db remotely

查看:70
本文介绍了无法远程连接到dockerized的mysql db的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 AWS ec2 服务器上,我安装了 docker 1.9.1 .在基于 ubuntu:trusty 官方docker映像的映像 test_image 中,我尝试设置LEMP(Linux,Nginx,MySQL,PHP)体系结构.

On my AWS ec2 server I have docker 1.9.1 installed. In an image test_image based from ubuntu:trusty official docker image, I have tried to setup the LEMP(Linux, Nginx, MySQL, PHP) architecture.

以下是我用来启动容器的docker命令:

Following is the docker command i have used to start my container:

docker run --name test_1 -d -p 80:80 -p 3306:3306 test_image /bin/sh -c "while true; do echo daemonized docker container; sleep 5000; done"

我已将端口 80 3306 暴露给主机的网络接口,并且还允许AWS的安全组允许与这些端口的入站连接.安全组中的连接类型为: MYSQL/Aurora ,协议为: TCP (我知道它不是很安全,仅用于初始实现.生产设置将有所不同)

I have exposed port 80 and 3306 to the host's network interface and have also allowed AWS's security group to allow inbound connections to these ports. Connection type in security group is: MYSQL/Aurora and protocol is: TCP (I know its not very secure, its only for initial implementation. Production setup will be different)

我遵循了这个DigitalOcean教程:

I followed this DigitalOcean tutorial: https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-14-04

安装Nginx并启动它之后,我可以通过ec2的公共IP在浏览器中对其进行测试,即 http://xxx.xxx.xxx.xxx 显示了默认的nginx欢迎页面.

After installing Nginx and starting it I am able to test it in the browser via ec2's pubic ip i.e. http://xxx.xxx.xxx.xxx shows the default nginx welcome page.

在安装MySQL时,我在docker容器中遵循了以下命令:

While installing MySQL, I followed the following commands in the docker container:

apt-get install mysql-server
mysql_install_db
/etc/init.d/mysql start
mysql_secure_installation

我已经为我的 root 用户提供了密码,并且在 mysql_secure_installation 期间,我允许远程访问root用户.

I have given a password to my root user and during mysql_secure_installation i had allowed remote access to root user.

mysql -u root -p 命令将我连接到mysql db,但不是从容器外部.

mysql -u root -p command from inside the container connects me to the mysql db but not from outside the container.

也从我的本地计算机上:我尝试使用mysql-client: mysql -h xxx.xxx.xxx.xxx -u root -p

Also from my local machine: I tried with mysql-client: mysql -h xxx.xxx.xxx.xxx -u root -p

我收到以下错误: ERROR 2003(HY000):无法连接到"xxx.xxx.xxx.xxx"(111)上的MySQL服务器

,也可以通过mysql工作台,但是我仍然无法连接到mysql数据库.

and also through mysql workbench but I still can't connect to the mysql db.

我在做什么错了?

推荐答案

在主机中,mysql的my.cnf将绑定地址设置为0.0.0.0,以便mysql在所有网络接口上侦听

In your host mysql's my.cnf set the bind address to 0.0.0.0 so that mysql listens on all network interfaces

bind-address = 0.0.0.0

默认配置为:

# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address   = 127.0.0.1

这篇关于无法远程连接到dockerized的mysql db的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆