[英]Connect to MySQL Server inside Docker container in an Microsoft Azure VM
I created an Ubuntu 15.10 VM on Microsoft Azure. 我在Microsoft Azure上创建了Ubuntu 15.10 VM。 On the Server i created a docker container with MySQL running (IP: 172.17.0.2)
在服务器上,我创建了一个运行MySQL的docker容器(IP:172.17.0.2)
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4255233555db mysql "/entrypoint.sh mysql" 16 hours ago Up 16 hours 0.0.0.0:3306->3306/tcp compose_mysql_1
I can connect over ssh to the VM and then access the MySQL-Server running in the docker container. 我可以通过ssh连接到VM,然后访问在docker容器中运行的MySQL-Server。
I now wanna have access to the MySQL-Server from the outside so that my WebApp on Microsoft Azure (same Ressource Group) can connect to the database. 现在,我想从外部访问MySQL-Server,以便我在Microsoft Azure(相同的资源组)上的WebApp可以连接到数据库。
I already forwarded the port 3306 of the VM to 172.17.0.2:3306. 我已经将虚拟机的端口3306转发到了172.17.0.2:3306。
With MySQL-Workbench from my local PC i can't connect to the MySQL-Server. 使用本地计算机上的MySQL-Workbench,我无法连接到MySQL-Server。 In fact i am not sure which credentials i need to provide to connect.
实际上,我不确定需要提供哪些凭据才能进行连接。 I tried it with the public ip of the VM and the root password of the MySQL-Server.
我尝试使用VM的公共IP和MySQL-Server的root密码进行尝试。 But shouldn't i somewhere also provide the password and user for the VM itself?
但是我不应该在某处也为虚拟机本身提供密码和用户吗?
Other than the firewall on the actual VM, Azure manage ports security using a separate VPC Network security group. 除了实际VM上的防火墙之外,Azure使用单独的VPC网络安全组管理端口安全。 By default, the Network group associated with your VM does not allow inbound TCP connections on port 3306. You have to add that manually:
默认情况下,与您的VM关联的Network组不允许端口3306上的入站TCP连接。您必须手动添加该端口:
Network interfaces
Network interfaces
Network security group
Network security group
Inbound security rules
Inbound security rules
Add
and Fill as follow Add
并填写,如下所示 Magic! 魔法!
I also had troubles getting the official MySQL image running and accessible. 我也很难运行和访问官方的MySQL映像。 sameersbn/docker-mysql provides an nice and easy wrapper that lets you specify user and database to be set up.
sameersbn / docker-mysql提供了一个简单易用的包装程序,可让您指定要设置的用户和数据库。
My docker-compose file has the following section: 我的docker-compose文件包含以下部分:
db:
image: sameersbn/mysql:latest
volumes:
- /opt/mysql/data:/var/lib/mysql
environment:
- DB_USER=${DB_USER}
- DB_PASS=${DB_PASS}
- DB_NAME=theDatabaseName
ports:
- "3306:3306"
The details: 细节:
image
- The above mentioned wrapper. image
-上述包装器。 volumes
- Mapping the data on the persistent host. volumes
-在持久主机上映射数据。 environment
- Variables that define the database setup. environment
-定义数据库设置的变量。 Either give plain text as with DB_NAME
or access environment variables through the ${...}
syntax. DB_NAME
一样提供纯文本,也可以通过${...}
语法访问环境变量。 ports
- Map out the port 3306 on the host so it may be accessed remotely. ports
映射主机上的端口3306,以便可以对其进行远程访问。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.