GithubHelp home page GithubHelp logo

emqx / emqx-docker Goto Github PK

View Code? Open in Web Editor NEW
19.0 4.0 8.0 71 KB

An Open-Source, Cloud-Native, Distributed MQTT Message Broker for IoT.

License: Apache License 2.0

Dockerfile 44.90% Shell 55.10%

emqx-docker's Introduction

EMQX

Quick reference

  • Where to get help:

https://emqx.io or https://github.com/emqx/emqx

  • Where to file issues:

https://github.com/emqx/emqx/issues

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/emqx:${tag}

For example

$ docker run -d --name emqx -p 18083:18083 -p 1883:1883 emqx/emqx:latest

The EMQX broker runs as Linux user emqx in the docker container.

Configuration

All EMQX Configuration in etc/emqx.conf can be configured via environment variables.

By default, the environment variables with EMQX_ prefix are mapped to key-value pairs in configuration files.

You can change the prefix by overriding HOCON_ENV_OVERRIDE_PREFIX.

Example:

EMQX_LISTENERS__SSL__DEFAULT__ACCEPTORS <--> listeners.ssl.default.acceptors
EMQX_ZONES__DEFAULT__MQTT__MAX_PACKET_SIZE <--> zones.default.mqtt.max_packet_size
  • Prefix EMQX_ is removed
  • All upper case letters is replaced with lower case letters
  • __ is replaced with .

If HOCON_ENV_OVERRIDE_PREFIX=DEV_ is set:

DEV_LISTENER__SSL__EXTERNAL__ACCEPTORS <--> listener.ssl.external.acceptors
DEV_MQTT__MAX_PACKET_SIZE              <--> mqtt.max_packet_size
DEV_LISTENERS__TCP__DEFAULT__BIND      <--> listeners.tcp.default.bind

For example, set MQTT TCP port to 1883

$ docker run -d --name emqx -e DEV_LISTENERS__TCP__DEFAULT__BIND=1883 -p 18083:18083 -p 1883:1883 emqx/emqx:latest

Please read more about EMQX configuration in the official documentation.

EMQX node name configuration

Options Default Mapped Description
EMQX_NAME container name none EMQX node short name
EMQX_HOST container IP none EMQX node host, IP or FQDN

These environment variables are used during container startup phase only in docker-entrypoint.sh.

If EMQX_NAME and EMQX_HOST are set, and EMQX_NODE_NAME is not set, EMQX_NODE_NAME=$EMQX_NAME@$EMQX_HOST. Otherwise EMQX_NODE_NAME is taken verbatim.

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 docker-compose.yaml:

    version: '3'
    
    services:
      emqx1:
        image: emqx/emqx:latest
        environment:
        - "EMQX_NAME=emqx"
        - "EMQX_HOST=node1.emqx.io"
        - "EMQX_CLUSTER__DISCOVERY_STRATEGY=static"
        - "EMQX_CLUSTER__STATIC__SEEDS=[[email protected], [email protected]]"
        networks:
          emqx-bridge:
            aliases:
            - node1.emqx.io
    
      emqx2:
        image: emqx/emqx:latest
        environment:
        - "EMQX_NAME=emqx"
        - "EMQX_HOST=node2.emqx.io"
        - "EMQX_CLUSTER__DISCOVERY_STRATEGY=static"
        - "EMQX_CLUSTER__STATIC__SEEDS=[[email protected], [email protected]]"
        networks:
          emqx-bridge:
            aliases:
            - node2.emqx.io
    
    networks:
      emqx-bridge:
        driver: bridge
  • Start the docker-compose cluster

    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 => ['[email protected]','[email protected]'],
                      stopped_nodes => []}

Persistence

If you want to persist the EMQX docker container, you need to keep the following directories:

  • /opt/emqx/data
  • /opt/emqx/etc
  • /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. In detail, one needs to specify the two environment variables: EMQX_NAME and EMQX_HOST, EMQX_HOST set as 127.0.0.1 or network alias would be useful.

In if you use docker-compose, the configuration would look something like this:

volumes:
  vol-emqx-data:
    name: foo-emqx-data
  vol-emqx-etc:
    name: foo-emqx-etc
  vol-emqx-log:
    name: foo-emqx-log

services:
  emqx:
    image: emqx/emqx:latest
    restart: always
    environment:
      EMQX_NAME: foo_emqx
      EMQX_HOST: 127.0.0.1
    volumes:
      - vol-emqx-data:/opt/emqx/data
      - vol-emqx-etc:/opt/emqx/etc
      - vol-emqx-log:/opt/emqx/log

Note that /opt/emqx/etc contains some essential configuration files. If you want to mount a host directory in the container to persist configuration overrides, you will need to bootstrap it with default configuration files.

Kernel 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/emqx:latest

REMEMBER: DO NOT RUN EMQX DOCKER PRIVILEGED OR MOUNT SYSTEM PROC IN CONTAINER TO TUNE LINUX KERNEL, IT IS UNSAFE.

Thanks

emqx-docker's People

Contributors

id avatar rory-z avatar yosifkit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

emqx-docker's Issues

Full mirror of docker emqx/emqx repository

Due to pull limits introduced by docker hub, nowadays it's hard to use docker hub without having separate IPs on k8s nodes, docker hub subscription or repushing images.

A lot of projects when their users faced these issues have created mirrors of images on GHCR and other places.
Cause you already publish some images in GHCR, could you please consider publishing same tags in this repo to use it as a mirror of docker hub?

Published artifacts changed

The amd64 artifact referenced in the Dockerfile has changed (without any version bump) and so the image fails to build. (The official images rebuild whenever the base image is updated to pull in security and package updates.) Assuming the new artifact is correct, it looks like the embedded sha256sum needs to be updated.

ENV EMQX_VERSION 4.4.3
ENV OTP otp24.1.5-3
RUN set -eu; \
arch=$(dpkg --print-architecture); \
if [ ${arch} = "amd64" ]; then sha256="7f7305566b977ef64afd31fed5fa71f7e79a5a934bf792422ac03e4f12768b02"; fi; \
if [ ${arch} = "arm64" ]; then sha256="34d3315c329de1d0fbf7419db1bff5007313f45de39e8be0ca5f04bad19f45a5"; fi; \
ID="$(sed -n '/^ID=/p' /etc/os-release | sed -r 's/ID=(.*)/\1/g' | sed 's/\"//g')"; \
VERSION_ID="$(sed -n '/^VERSION_ID=/p' /etc/os-release | sed -r 's/VERSION_ID=(.*)/\1/g' | sed 's/\"//g')"; \
pkg="emqx-${EMQX_VERSION}-${OTP}-${ID}${VERSION_ID}-${arch}.zip"; \
curl -f -O -L https://www.emqx.com/en/downloads/broker/${EMQX_VERSION}/${pkg}; \
echo "$sha256 *$pkg" | sha256sum -c || exit 1; \

Failed build:

Step 5/13 : RUN set -eu;     arch=$(dpkg --print-architecture);     if [ ${arch} = "amd64" ]; then sha256="7f7305566b977ef64afd31fed5fa71f7e79a5a934bf792422ac03e4f12768b02"; fi;     if [ ${arch} = "arm64" ]; then sha256="34d3315c329de1d0fbf7419db1bff5007313f45de39e8be0ca5f04bad19f45a5"; fi;     ID="$(sed -n '/^ID=/p' /etc/os-release | sed -r 's/ID=(.*)/\1/g' | sed 's/\"//g')";     VERSION_ID="$(sed -n '/^VERSION_ID=/p' /etc/os-release | sed -r 's/VERSION_ID=(.*)/\1/g' | sed 's/\"//g')";     pkg="emqx-${EMQX_VERSION}-${OTP}-${ID}${VERSION_ID}-${arch}.zip";     curl -f -O -L https://www.emqx.com/en/downloads/broker/${EMQX_VERSION}/${pkg};     echo "$sha256 *$pkg" | sha256sum -c || exit 1;     unzip -q -d /opt $pkg;     ln -s /opt/emqx/bin/* /usr/local/bin/;     rm -rf $pkg
 ---> Running in e63dee74f885
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
 34 43.3M   34 14.9M    0     0  11.2M      0  0:00:03  0:00:01  0:00:02 16.8M
 65 43.3M   65 28.2M    0     0  12.1M      0  0:00:03  0:00:02  0:00:01 14.9M
 76 43.3M   76 33.3M    0     0  10.0M      0  0:00:04  0:00:03  0:00:01 11.5M
 95 43.3M   95 41.4M    0     0  9815k      0  0:00:04  0:00:04 --:--:-- 10.6M
100 43.3M  100 43.3M    0     0  9742k      0  0:00:04  0:00:04 --:--:-- 10.5M
emqx-4.4.3-otp24.1.5-3-debian11-amd64.zip: FAILED
sha256sum: WARNING: 1 computed checksum did NOT match

Docker run fail

image

[root@localhost ~]# cat /etc/os-release 
NAME="Rocky Linux"
VERSION="9.2 (Blue Onyx)"
ID="rocky"
ID_LIKE="rhel centos fedora"
VERSION_ID="9.2"
PLATFORM_ID="platform:el9"
PRETTY_NAME="Rocky Linux 9.2 (Blue Onyx)"
ANSI_COLOR="0;32"
LOGO="fedora-logo-icon"
CPE_NAME="cpe:/o:rocky:rocky:9::baseos"
HOME_URL="https://rockylinux.org/"
BUG_REPORT_URL="https://bugs.rockylinux.org/"
SUPPORT_END="2032-05-31"
ROCKY_SUPPORT_PRODUCT="Rocky-Linux-9"
ROCKY_SUPPORT_PRODUCT_VERSION="9.2"
REDHAT_SUPPORT_PRODUCT="Rocky Linux"
REDHAT_SUPPORT_PRODUCT_VERSION="9.2"
[root@localhost ~]# docker version
Client: Docker Engine - Community
 Version:           24.0.7
 API version:       1.43
 Go version:        go1.20.10
 Git commit:        afdd53b
 Built:             Thu Oct 26 09:09:13 2023
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          24.0.7
  API version:      1.43 (minimum version 1.12)
  Go version:       go1.20.10
  Git commit:       311b9ff
  Built:            Thu Oct 26 09:07:45 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.24
  GitCommit:        61f9fd88f79f081d64d6fa3bb1a0dc71ec870523
 runc:
  Version:          1.1.9
  GitCommit:        v1.1.9-0-gccaecfc
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

node.name environment variable

EMQX documentation shows that the environment variable to be set for node.name should be EMQX_NODE__NAME (two underscores), but docker-entrypoint.sh only honors setting the node.name with EMQX_NODE_NAME (one underscore).

I also was confused like #44 because the Github link from the documentation takes you to the other emqx package source. I'm not sure which one I should be using emqx or emqx/emqx. Docs say emqx. Extremely confusing.

How to comment a configuration option?

Hi, I'm using Postgres as authentication, how do I disable EMQX_AUTH__PGSQL__ACL_QUERY? I don't have ACL table created, and I don't want EMQX to attempt to make query.

Or in general, how can I comment out a configuration?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.