emqtt 2.3.4 with support for WSS with certificates from Lets Encrypt
650
EMQ (Erlang MQTT Broker) is a distributed, massively scalable, highly extensible MQTT message broker written in Erlang/OTP.
Docker image home:
Current docker image size: 77.6 MB
docker pull devrealm/emqtt
docker run --restart=always -ti --name emqtt -p 18083:18083 -p 1883:1883 -p 8083:8083 -p 8443:8443 -p 8084:8084 -p 8080:8080 -e "EMQ_LOG_LEVEL=debug" -e "EMQ_ADMIN_PASSWORD=your_password" -e "EMQ_NAME=emqtt_broker" -d devrealm/emqtt
The emqtt erlang broker runs as linux user emqtt in the docker container.
Mqtt client authentication can be provided using an authentication file and change in the container configuration.
First, create the emq_auth_username.conf configuration file in the host:
##--------------------------------------------------------------------
## Username Authentication Plugin
##--------------------------------------------------------------------
## Examples:
auth.user.1.username = user1
auth.user.1.password = pass1234
auth.user.2.username = user2
auth.user.2.password = pass1234
##auth.user.1.username = admin
##auth.user.1.password = public
##auth.user.2.username = [email protected]
##auth.user.2.password = public
##auth.user.3.username = name~!@#$%^&*()_+
##auth.user.3.password = pwsswd~!@#$%^&*()_+
And then run the container using:
docker run --restart=always -ti --name emqtt -p 18083:18083 -p 1883:1883 -p 8083:8083 -p 8443:8443 -p 8084:8084 -p 8080:8080 -e "EMQ_MQTT__ALLOW_ANONYMOUS=false" -e "EMQ_LOG_LEVEL=debug" -e "EMQ_ADMIN_PASSWORD=your_password" -e "EMQ_LOADED_PLUGINS=emq_recon,emq_modules,emq_retainer,emq_dashboard,emq_auth_username" -e "EMQ_NAME=emqtt_broker" -v /host/folder/emq_auth_username.conf:/opt/emqttd/etc/plugins/emq_auth_username.conf -d devrealm/emqtt
In order for the broker to run with Let's Encrypt certificates use the following docker run command:
docker run --restart=always -ti --name emqtt -p 18083:18083 -p 1883:1883 -p 8083:8083 -p 8443:8443 -p 8084:8084 -p 8080:8080 -v /etc/letsencrypt/live/yourdomain.com/privkey.pem:/opt/emqttd/etc/certs/key.pem -v /etc/letsencrypt/live/yourdomain.com/fullchain.pem:/opt/emqttd/etc/certs/cert.pem -e "EMQ_LOG_LEVEL=debug" -e "EMQ_ADMIN_PASSWORD=your_password" -d devrealm/emqtt
Notice the :
-v /etc/letsencrypt/live/yourdomain.com/privkey.pem:/opt/emqttd/etc/certs/key.pem-v /etc/letsencrypt/live/yourdomain.com/fullchain.pem:/opt/emqttd/etc/certs/cert.pemUse the environment variable to configure the EMQ docker container
The environment variables which with EMQ_ prefix are mapped to configuration file, . get replaced by __.
Example:
EMQ_LISTENER__SSL__EXTERNAL__ACCEPTORS <--> listener.ssl.external.acceptors
EMQ_MQTT__MAX_PACKET_SIZE <--> mqtt.max_packet_size
Also the environment variables which with PLATFORM_ prefix are mapped to template string in configuration file.
PLATFORM_ETC_DIR <--> {{ platform_etc_dir }}
Non mapped environment variables:
EMQ_NAME
EMQ_HOST
These environment variables will ignore for configuration file.
NOTE: All EMQ Configuration in etc/emq.conf could config by environment. The following list is just an example, not a complete configuration.
| Options | Default | Mapped | Description |
|---|---|---|---|
| EMQ_NAME | container name | none | emq node short name |
| EMQ_HOST | container IP | none | emq node host, IP or FQDN |
| EMQ_WAIT_TIME | 5 | none | wait time in sec before timeout |
| EMQ_JOIN_CLUSTER | none | none | Initial cluster to join |
| EMQ_ADMIN_PASSWORD | public | none | emq admin password |
| PLATFORM_ETC_DIR | /opt/emqtt/etc | {{ platform_etc_dir }} | The etc directory |
| PLATFORM_LOG_DIR | /opt/emqtt/log | {{ platform_log_dir }} | The log directory |
| EMQ_NODE__NAME | EMQ_NAME@EMQ_HOST | node.name | Erlang node name, name@ipaddress/host |
| EMQ_NODE__COOKIE | emq_dist_cookie | node.cookie | cookie for cluster |
| EMQ_LOG__CONSOLE | console | log.console | log console output method |
| EMQ_MQTT__ALLOW_ANONYMOUS | true | mqtt.allow_anonymous | allow mqtt anonymous login |
| EMQ_LISTENER__TCP__EXTERNAL | 1883 | listener.tcp.external | MQTT TCP port |
| EMQ_LISTENER__SSL__EXTERNAL | 8883 | listener.ssl.external | MQTT TCP TLS/SSL port |
| EMQ_LISTENER__WS__EXTERNAL | 8083 | listener.ws.external | HTTP and WebSocket port |
| EMQ_LISTENER__WSS__EXTERNAL | 8084 | listener.wss.external | HTTPS and WSS port |
| EMQ_LISTENER__API__MGMT | 8080 | listener.api.mgmt | mgmt API port |
| EMQ_MQTT__MAX_PACKET_SIZE | 64KB | mqtt.max_packet_size | Max Packet Size Allowed |
The list is incomplete and may changed with etc/emq.conf and plugin configuration files. But the mapping rule is similar.
If set EMQ_NAME and EMQ_HOST, and unset EMQ_NODE__NAME, EMQ_NODE__NAME=$EMQ_NAME@$EMQ_HOST.
For example, set mqtt tcp port to 1883
docker run --rm -ti --name emq -e EMQ_LISTENER__TCP__EXTERNAL=1883 -p 18083:18083 -p 1883:1883 devrealm/emqtt
| Oprtions | Default | Description |
|---|---|---|
| EMQ_LOADED_PLUGINS | see content below | default plugins emq loaded |
Default environment variable EMQ_LOADED_PLUGINS, including
emq_reconemq_modulesemq_retaineremq_dashboard# The default EMQ_LOADED_PLUGINS env
EMQ_LOADED_PLUGINS="emq_recon,emq_modules,emq_retainer,emq_dashboard"
For example, load emq_auth_redis plugin, set it into EMQ_LOADED_PLUGINS and use any separator to separates it.
You can use comma, space or other separator that you want.
All the plugin you defined in env EMQ_LOADED_PLUGINS will be loaded.
EMQ_LOADED_PLUGINS="emq_auth_redis,emq_recon,emq_modules,emq_retainer,emq_dashboard"
EMQ_LOADED_PLUGINS="emq_auth_redis emq_recon emq_modules emq_retainer emq_dashboard"
EMQ_LOADED_PLUGINS="emq_auth_redis | emq_recon | emq_modules | emq_retainer | emq_dashboard"
The environment variables which with EMQ_ prefix are mapped to all emq plugins' configuration file, . get replaced by __.
Example:
EMQ_AUTH__REDIS__SERVER <--> auth.redis.server
EMQ_AUTH__REDIS__PASSWORD <--> auth.redis.password
Don't worry about where to find the configuration file of emq plugins, this docker image will find and config them automatically using some magic.
All plugin of emq project could config in this way, following the environment variables mapping rule above.
Assume you are using redis auth plugin, for example:
#EMQ_AUTH__REDIS__SERVER="redis.at.yourserver"
#EMQ_AUTH__REDIS__PASSWORD="password_for_redis"
docker run --rm -ti --name emq -p 18083:18083 -p 1883:1883 -p 4369:4369 \
-e EMQ_LISTENER__TCP__EXTERNAL=1883 \
-e EMQ_LOADED_PLUGINS="emq_auth_redis,emq_recon,emq_modules,emq_retainer,emq_dashboard" \
-e EMQ_AUTH__REDIS__SERVER="your.redis.server:6379" \
-e EMQ_AUTH__REDIS__PASSWORD="password_for_redis" \
-e EMQ_AUTH__REDIS__PASSWORD_HASH=plain \
devrealm/emqtt
You can specify a initial cluster and join.
Note: You must publsh port 4369 and range of port 6000-6999 for EMQ Clustered.
For example, using 6000-6100 for cluster.
docker run --rm -ti --name emq -p 18083:18083 -p 1883:1883 -p 4369:4369 -p 6000-6100:6000-6100 \
-e EMQ_NAME="emq" \
-e EMQ_HOST="s2.emqtt.io" \
-e EMQ_LISTENER__TCP__EXTERNAL=1883 \
-e EMQ_JOIN_CLUSTER="[email protected]" \
devrealm/emqtt
Under linux host machine, the easiest way is tuning host machine's kernel.
If you want tune linux kernel by docker, you must ensure your docker is latest version (>=1.12).
docker run --rm -ti --name emq -p 18083:18083 -p 1883:1883 -p 4369:4369 \
--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
REMEMBER: DO NOT RUN EMQ DOCKER PRIVILEGED OR MOUNT SYSTEM PROC IN CONTAINER TO TUNE LINUX KERNEL, IT IS UNSAFE.
Report issues here: https://github.com/devrealm/emq-docker/issues
Content type
Image
Digest
Size
44.6 MB
Last updated
over 8 years ago
docker pull devrealm/emqtt