Comments (5)
@SergeTupchiy
Regarding what you said, use the docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' mysql
command to get the IP address of Mysql, and then use this in the connector configuration It is feasible to connect to Mysql using IP+Port👍
The address of the configured Mysql server is the IP obtained by docker inspect
+ the port 3306 inside the container
Thank you for your patient reply
from emqx.
Hi @gongna-au,
Docker containers are isolated, EMQX running in a docker container can't reach MySql running in another container at 127.0.0.1:3307
even though you have bound Mysql container port to host port with -p 3307:3306
.
You need to create a Docker network so that containers can communicate with each other, though it would be easier to use docker-compose
and define EMQX and MySql services.
Another quick work-around is to use Docker container IP address, but this can be changed after each container restart:
# Set this IP address to the bridge config:
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' mysql
from emqx.
非常感谢@SergeTupchiy 的回复😘
创建Docker网络
docker network create my-network
运行emqx
docker run -d --name emqx-enterprise --network my-network -p 1883:1883 -p 8083:8083 -p 8084:8084 -p 8883:8883 -p 18083:18083 emqx/emqx-enterprise:5.6.0
运行Mysql
docker run --name mysql --network my-network -p 3307:3306 -e MYSQL_ROOT_PASSWORD=public -d mysql
创建数据库和表
docker exec -it mysql bash
mysql -u root -ppublic
CREATE DATABASE emqx_data CHARACTER SET utf8mb4;
use emqx_data;
CREATE TABLE emqx_messages (id INT AUTO_INCREMENT PRIMARY KEY,clientid VARCHAR(255),topic VARCHAR(255),payload BLOB,created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
CREATE TABLE emqx_client_events (id INT AUTO_INCREMENT PRIMARY KEY,clientid VARCHAR(255), event VARCHAR(255),created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
仪表盘连接
输入的Mysql地址为mysql
而不是127.0.0.1:3307
至此访问http://localhost:18083/#/connector/create
可以成功创建Mysql连接器
from emqx.
非常感谢@SergeTupchiy 的回复
我又尝试让emqx 和Mysql都运行在宿主机--network host
,而不是创建Docker网络,也成功解决了我之前的疑惑。
运行emqx
docker run -d --name emqx-enterprise --network host emqx/emqx-enterprise:5.6.0
这条命令会启动一个名为emqx-enterprise的容器,该容器直接使用宿主机的网络。这意味着,任何EMQX企业版在容器内监听的端口(例如1883, 8083, 8084, 8883, 18083)都会直接在宿主机上开放,无需进行端口映射。
注意事项:
确保宿主机的这些端口(1883, 8083, 8084, 8883, 18083)未被其他服务占用。
运行Mysql
docker run --name mysql --network host -e MYSQL_ROOT_PASSWORD=public -d mysql
这条命令将启动一个名为mysql的容器,容器直接使用宿主机的网络。MySQL服务将在其默认端口3306上监听,而不是通过Docker在宿主机上映射到3307端口。
注意事项:
由于容器使用宿主机网络,MySQL服务将在宿主机的3306端口上直接对外开放。如果宿主机上已经有服务监听3306端口(例如另一个MySQL实例),则可能会导致端口冲突。
创建数据库和表
docker exec -it mysql bash
mysql -u root -ppublic
CREATE DATABASE emqx_data CHARACTER SET utf8mb4;
use emqx_data;
CREATE TABLE emqx_messages (id INT AUTO_INCREMENT PRIMARY KEY,clientid VARCHAR(255),topic VARCHAR(255),payload BLOB,created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
CREATE TABLE emqx_client_events (id INT AUTO_INCREMENT PRIMARY KEY,clientid VARCHAR(255), event VARCHAR(255),created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
当使用--network host参数运行Docker容器时,容器会直接使用host的网络命名空间。这意味着容器中的应用程序将直接在后续机的网络上运行,而不是在Docker自己的虚拟网络中因此,使用--network host时指定的任何如图所示的端口映射(-p或--publish参数)都将被忽略,正如 Docker 运行时给出的警告:
WARNING: Published ports are discarded when using host network mode
这是因为在host网络模式下,容器与一个宿主机共享网络堆栈,容器内的服务可以直接监听对应的端口,而不是需要通过Docker进行端口映射。,比如EMQX或MySQL,它们将直接在对应机的对应端口上可用,而不需要Docker来管理端口映射。
创建Mysql连接器
输入的Mysql地址为127.0.0.1:3306 而不是127.0.0.1:3307或者直接是mysql 🤔
from emqx.
Happy to help, @gongna-au!
from emqx.
Related Issues (20)
- Unable to force-leave stale nodes HOT 12
- Enhanced Authentication Failed with Reason Code 135 (Not Authorized). HOT 9
- Configuration fails to take effect about TCP Keep Alive behavior HOT 6
- Grafana dashboard should use $__rate_interval HOT 3
- Customizable HTTP Server Actions (Sink) Retry Policies HOT 2
- Can not view retained messages in admin dashboard after updating to 5.6.0 from 5.5.1 HOT 7
- 使用 MongoDB4.0 进行密码认证,无法成功接入数据源。 HOT 6
- Can't add users on touch screen device HOT 7
- Action output to external HTTP server - authorization header issue HOT 2
- The client disconnects after publish message whose topic starts with '$' HOT 2
- Not getting Emqx dashboard HOT 1
- EMQX Clustering - Message Replication HOT 4
- STOMP GW does not send heartbeat to client HOT 4
- EMQX cluster cannot restart after persistence HOT 1
- After STOMP enables authentication, authentication fails when the account password carries a colon
- runq_overload everyday for few minutes HOT 4
- Receive Maximum Not Sent in Bridge CONNACK HOT 4
- ~10ms latency on publishing and receiving message on the same machine on windows HOT 6
- webhook监听上下线事件时,事件时序有误,原因不明(connected and disconnected events may out of order) HOT 3
- Authentication fails periodically and restart fixes it HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from emqx.