EMQX Open Source MQTT Broker
Stack
Open-source MQTT broker for IoT, IIoT, and connected vehicles - Single Broker deployment
Image details
Configuration
TypeComposelinuxemqx:5.5.01883:18838083:80838084:80848883:888318083:18083/opt/emqx/data : emqx_data/opt/emqx/log : emqx_logEMQX_DASHBOARD__DEFAULT_USERNAME=${EMQX_DASHBOARD__DEFAULT_USERNAME}EMQX_DASHBOARD__DEFAULT_PASSWORD=${EMQX_DASHBOARD__DEFAULT_PASSWORD}unless-stoppedStandalone Install
Select an install method, to see config/commands for deploying EMQX Open Source MQTT Broker
Install on Portainer
Import all app templates into your Portainer instance, for easy 1-click deploys
- Ensure both Docker and Portainer are installed, and up-to-date
- Log into your Portainer web UI
- Under Settings → App Templates, paste the below URL
- Head to Home → App Templates, and the list of apps will show up
- Select EMQX Open Source MQTT Broker, fill in any config options, and hit Deploy
Template Import URL
https://raw.githubusercontent.com/Lissy93/portainer-templates/main/templates.json
Show Me
Original stackfile
The compose file this template deploys, straight from its repo:
version: '3'
services:
emqx:
image: emqx:5.5.0
container_name: emqx
restart: unless-stopped
healthcheck:
test: ["CMD", "/opt/emqx/bin/emqx", "ctl", "status"]
interval: 5s
timeout: 25s
retries: 5
networks:
emqx_bridge:
environment:
- EMQX_DASHBOARD__DEFAULT_USERNAME=${EMQX_DASHBOARD__DEFAULT_USERNAME}
- EMQX_DASHBOARD__DEFAULT_PASSWORD=${EMQX_DASHBOARD__DEFAULT_PASSWORD}
ports:
- 1883:1883
- 8083:8083
- 8084:8084
- 8883:8883
- 18083:18083
volumes:
- emqx_data:/opt/emqx/data
- emqx_log:/opt/emqx/log
networks:
emqx_bridge:
volumes:
emqx_data:
emqx_log:
Or deploy it directly from the source:
git clone https://github.com/portainer/templates
cd templates
docker compose -f edge/emqx/docker-compose.yml up -dMore install options in our documentation.
DEPRECATION NOTICE
Starting from v5.9.0, EMQX has unified all features from the previous Open Source and Enterprise editions into a single, powerful offering with the Business Source License (BSL) 1.1.If you want to understand why we made the change, please read this blog post, and if you want to know more about the new license, please read the EMQX Licensing FAQ.
Consequently, we stopped publishing the
emqx Docker Official Image. EMQX v5.9.0+ will only be available in the emqx/emqx and emqx/emqx-enterprise Docker Hub repositories.Quick reference
- Maintained by:
[EMQ Technologies](https://github.com/emqx)- Where to get help:
[Discussions](https://github.com/emqx/emqx/discussions) or [Discord](https://discord.gg/xYGf3fQnES)Supported tags and respective Dockerfile links
Quick reference (cont.)
- Where to file issues:
[https://github.com/emqx/emqx-docker/issues](https://github.com/emqx/emqx-docker/issues?q=)- Supported architectures: (more info)
[`amd64`](https://hub.docker.com/r/amd64/emqx/), [`arm64v8`](https://hub.docker.com/r/arm64v8/emqx/)- Published image artifact details:
[repo-info repo's `repos/emqx/` directory](https://github.com/docker-library/repo-info/blob/master/repos/emqx) ([history](https://github.com/docker-library/repo-info/commits/master/repos/emqx))
(image metadata, transfer size, etc)- Image updates:
[official-images repo's `library/emqx` label](https://github.com/docker-library/official-images/issues?q=label%3Alibrary%2Femqx)
[official-images repo's `library/emqx` file](https://github.com/docker-library/official-images/blob/master/library/emqx) ([history](https://github.com/docker-library/official-images/commits/master/library/emqx))- Source of this description:
[docs repo's `emqx/` directory](https://github.com/docker-library/docs/tree/master/emqx) ([history](https://github.com/docker-library/docs/commits/master/emqx))What is EMQX
EMQX is the world's most scalable open-source MQTT broker with a high performance that connects 100M+ IoT devices in 1 cluster, while maintaining 1M message per second throughput and sub-millisecond latency.EMQX supports multiple open standard protocols like MQTT, HTTP, QUIC, and WebSocket. It's 100% compliant with MQTT 5.0 and 3.x standard, and secures bi-directional communication with MQTT over TLS/SSL and various authentication mechanisms.
With the built-in powerful SQL-based rules engine, EMQX can extract, filter, enrich and transform IoT data in real-time. In addition, it ensures high availability and horizontal scalability with a masterless distributed architecture, and provides ops-friendly user experience and great observability.
EMQX boasts more than 20K+ enterprise users across 50+ countries and regions, connecting 100M+ IoT devices worldwide, and is trusted by over 400 customers in mission-critical scenarios of IoT, IIoT, connected vehicles, and more, including over 70 Fortune 500 companies like HPE, VMware, Verifone, SAIC Volkswagen, and Ericsson.
How to use this image
Run EMQX
Execute some command under this docker image$ docker run -d --name emqx emqx:${tag}For example
$ docker run -d --name emqx -p 18083:18083 -p 1883:1883 emqx:latestThe EMQX broker runs as Linux user
emqx in the docker container.Configuration
All EMQX Configuration inetc/emqx.conf can be configured via environment variables.Example:
EMQX_DASHBOARD__DEFAULT_PASSWORD <--> dashboard.default_password
EMQX_NODE__COOKIE <--> node.cookie
EMQX_LISTENERS__SSL__default__ENABLE <--> listeners.ssl.default.enableNote: The lowercase use of 'default' is not a typo. It is used to demonstrate that lowercase environment variables are equivalent.- Prefix
EMQX_is removed - All upper case letters are replaced with lower case letters
__is replaced with.
For example, set MQTT TCP port to 1883
$ docker run -d --name emqx -e EMQX_DASHBOARD__DEFAULT_PASSWORD=mysecret -p 18083:18083 -p 1883:1883 emqx:latestPlease read more about EMQX configuration in the official documentation
EMQX node name configuration
Environment variableEMQX_NODE__NAME allows you to specify an EMQX node name, which defaults to <container_name>@<container_ip>.If not specified, EMQX determines its node name based on the running environment or other environment variables used for node discovery.
Cluster
EMQX supports a variety of clustering methods, see our documentation for details.Let's create a static node list cluster from Docker Compose.
- Create
compose.yaml:
services:
emqx1:
image: emqx:latest
environment:
- "EMQX_NODE__NAME=emqx@node1.emqx.io"
- "EMQX_CLUSTER__DISCOVERY_STRATEGY=static"
- "EMQX_CLUSTER__STATIC__SEEDS=[emqx@node1.emqx.io, emqx@node2.emqx.io]"
networks:
emqx-bridge:
aliases:
- node1.emqx.io
emqx2:
image: emqx:latest
environment:
- "EMQX_NODE__NAME=emqx@node2.emqx.io"
- "EMQX_CLUSTER__DISCOVERY_STRATEGY=static"
- "EMQX_CLUSTER__STATIC__SEEDS=[emqx@node1.emqx.io, emqx@node2.emqx.io]"
networks:
emqx-bridge:
aliases:
- node2.emqx.io
networks:
emqx-bridge:
driver: bridge- Start the Docker Compose services
docker compose -p my_emqx up -d- View cluster
$ docker exec -it my_emqx_emqx1_1 sh -c "emqx ctl cluster status"
Cluster status: #{running_nodes => ['emqx@node1.emqx.io','emqx@node2.emqx.io'],
stopped_nodes => []}Persistence
If you want to persist the EMQX docker container, you need to keep the following directories:/opt/emqx/data/opt/emqx/log
Since data in these folders are partially stored under the
/opt/emqx/data/mnesia/${node_name}, the user also needs to reuse the same node name to see the previous state. To make this work, one needs to set the host part of EMQX_NODE__NAME to something static that does not change when you restart or recreate the container. It could be container name, hostname or loopback IP address 127.0.0.1 if you only have one node.In if you use Docker Compose, the configuration would look something like this:
volumes:
vol-emqx-data:
name: foo-emqx-data
vol-emqx-log:
name: foo-emqx-log
services:
emqx:
image: emqx:latest
restart: always
environment:
EMQX_NODE__NAME: foo_emqx@127.0.0.1
volumes:
- vol-emqx-data:/opt/emqx/data
- vol-emqx-log:/opt/emqx/logKernel Tuning
Under Linux host machine, the easiest way is Tuning guide.If you want tune Linux kernel by docker, you must ensure your docker is latest version (>=1.12).
docker run -d --name emqx -p 18083:18083 -p 1883:1883 \
--sysctl fs.file-max=2097152 \
--sysctl fs.nr_open=2097152 \
--sysctl net.core.somaxconn=32768 \
--sysctl net.ipv4.tcp_max_syn_backlog=16384 \
--sysctl net.core.netdev_max_backlog=16384 \
--sysctl net.ipv4.ip_local_port_range=1000 65535 \
--sysctl net.core.rmem_default=262144 \
--sysctl net.core.wmem_default=262144 \
--sysctl net.core.rmem_max=16777216 \
--sysctl net.core.wmem_max=16777216 \
--sysctl net.core.optmem_max=16777216 \
--sysctl net.ipv4.tcp_rmem=1024 4096 16777216 \
--sysctl net.ipv4.tcp_wmem=1024 4096 16777216 \
--sysctl net.ipv4.tcp_max_tw_buckets=1048576 \
--sysctl net.ipv4.tcp_fin_timeout=15 \
emqx:latestREMEMBER: DO NOT RUN EMQX DOCKER PRIVILEGED OR MOUNT SYSTEM PROC IN CONTAINER TO TUNE LINUX KERNEL, IT IS UNSAFE.
License
View license information for the software contained in this image.As with all Docker images, these likely also contain other software which may be under other licenses (such as Bash, etc from the base distribution, along with any direct or indirect dependencies of the primary software being contained).
Some additional license information which was able to be auto-detected might be found in the
repo-info repository's emqx/ directory.As for any pre-built image usage, it is the image user's responsibility to ensure that any use of this image complies with any relevant licenses for all software contained within.
Serve EMQX Open Source MQTT Broker on your own domain behind Caddy, Nginx or Traefik. Fill in your domain and copy the result. It's a starting point, some apps need their own base URL or extra headers set too.
Proxying emqx-open-source-mqtt-broker.example.com to http://emqx:1883
Add this to your Caddyfile
emqx-open-source-mqtt-broker.example.com {
reverse_proxy http://emqx:1883
}Check the logs first
Nine times out of ten the logs tell you exactly what went wrong.
- In Portainer, go to Containers, click the container, then Logs. Or run
docker logs <container> - Exit codes help too:
137means killed, usually out of memory.126or127means the command inside the image is broken.
Port already in use
If deployment fails with "Bind for 0.0.0.0:1883 failed: port is already allocated", something else on your server is using that port.
- Find what's using it:
sudo ss -tlnp | grep :1883 - Stop the other service, or pick a different host port. In
1883:1883only the left number is yours to change, the right one belongs to the app.
Running but the page won't load
The container is up but nothing appears in your browser.
- Use your server's real IP:
http://your-server-ip:1883. The 0.0.0.0 link Portainer shows isn't a real address. - Give it a minute after first deploy, emqx can take a while to initialise.
- Make sure your firewall allows the port, e.g.
sudo ufw allow 1883
Image won't pull
Test the pull directly on the host: docker pull emqx:5.5.0
- "manifest unknown" means the tag no longer exists.
- "toomanyrequests" is the Docker Hub rate limit. Log in with
docker loginto raise it. - "no space left on device" means a full disk. Reclaim space with
docker system prune
"exec format error"
This means the image was built for a different CPU architecture than your server.
- This image supports:
amd64, arm64, arm64/v8 - Check yours with
uname -m: x86_64 is amd64, aarch64 is arm64. Raspberry Pi and other ARM boards are the usual culprits.
Container keeps restarting
The unless-stopped restart policy relaunches the app after every crash, so the real error can scroll past.
- Check the logs right after a restart, the last few lines before it died are the useful ones.
- Get the exit code with
docker inspect <container> --format '{{.State.ExitCode}}' - Still stuck? Redeploy once with the restart policy set to
noso the failure stays visible.
Stack won't deploy
Compose stacks fail fast on small mistakes, and Portainer shows the reason just above the editor.
- YAML only accepts spaces for indentation, a single tab breaks the whole file.
Raise an issue
Found something which isn't working as it should? Here's how to report it.
- Bug within the app: Open an issue within emqx's repo
- Template not working: Open an issue on portainer/templates
- This website not working: Open an issue on lissy93/portainer-templates
A Compose stack
EMQX Open Source MQTT Broker is a Compose stack, a set of containers defined in one file and brought up together by Portainer, then started and stopped as a single app.
The app image
An image is the app packed up ready to go, everything EMQX Open Source MQTT Broker needs bundled into one download. This template pulls emqx:5.5.0, which Docker fetches once (about 103 MB) and then starts your own copy from.
Where the image comes from
Docker pulls its images from registries, public libraries of ready-built apps. EMQX Open Source MQTT Broker's comes from Docker Hub as one of its official, curated images.
Version tags
The bit after the colon in the image name is the version tag. This one pins 5.5.0, so every redeploy gives you that exact build until you bump it yourself.
Which machines it runs on
Every image is built for particular CPU types. This one ships for amd64, arm64, arm64/v8, so it runs on both regular x86 servers and ARM boards like a Raspberry Pi.
Ports
A port is the door the app answers on. A mapping like 1883:1883 means it's reachable on port 1883 of your server, where the left number is yours to change and the right one belongs to the app. It opens:
1883:18838083:80838084:80848883:888318083:18083
Volumes
A volume is where EMQX Open Source MQTT Broker keeps its files so they survive an update or a restart. Without one, anything it saves would sit inside the container and vanish the moment it's recreated. This template mounts:
/opt/emqx/datakept in theemqx_datavolume Docker manages/opt/emqx/logkept in theemqx_logvolume Docker manages
Environment variables
Environment variables are the settings you hand over when you deploy, things like a password or a timezone. EMQX Open Source MQTT Broker takes 2 of them, all with defaults you can leave alone or tweak:
EMQX_DASHBOARD__DEFAULT_USERNAME, pulled from your own environment. EMQX Dashboard UsernameEMQX_DASHBOARD__DEFAULT_PASSWORD, pulled from your own environment. EMQX Dashboard Password
Restart policy
The restart policy here is unless-stopped, so Docker restarts EMQX Open Source MQTT Broker after a crash or reboot, but leaves it off when you stop it on purpose. You can change this on the deploy screen. The choices are no (never restart), on-failure (only after a crash), unless-stopped (restart unless you stop it), and always (bring it back no matter what).
Health check
A health check is how Docker tells whether EMQX Open Source MQTT Broker is really working, not just switched on. It runs /opt/emqx/bin/emqx ctl status every 5s and flags the container as unhealthy if that keeps failing.
Networking
Nothing custom is set, so EMQX Open Source MQTT Broker sits on Docker's default bridge network: its own private space that reaches the outside world only through the ports it publishes.
Container name
Once it's deployed, Portainer names the container emqx. That's what you'll spot in the containers list and use in commands like docker logs emqx.
Platform
The platform is linux, the kind of system the container is built to run on. Docker and Portainer handle this on a normal Linux server.
Portainer app templates
Zooming out, this whole page comes from a Portainer app template: a short recipe telling Portainer how to set EMQX Open Source MQTT Broker up. Add the template list to Portainer once, then deploying EMQX Open Source MQTT Broker is a click rather than a wall of config.
Anyviz Cloud Adaptor edge
- CockroachDB (stack) edge
Floating License Server edge
Grafana Dashboard edge
Inductive Automation - Ignition Gateway edge
InfluxDB for Edge edge
Litmus Edge edge
Litmus Edge Digital Factory Demo edge
MaestroHub edge
Manubes Edge Node edge
OPC Router edge
Pro Mosquitto with Management Center edge