# Deploy with Docker

This chapter introduces how to use the official Docker image to install and run NanoMQ, and provides some ways to configure it;

# Use Docker to run NanoMQ

This section will introduce how to use the Docker image to install the latest version of NanoMQ. If you want to work with other versions, please visit the NanoMQ Deployment page (opens new window).

  1. To get the Docker image, run:
docker pull emqx/nanomq:lastest
  1. To start the Docker container, run:
docker run -d --name nanomq -p 1883:1883 -p 8083:8083 -p 8883:8883 emqx/nanomq:latest

For more information about NanoMQ official docker image, see Docker Hub - nanomq (opens new window)

# Configuring

Here are some ways to modify configuration file on Docker container:

  • Modify /etc/nanomq.conf on docker container, refer to configruation description
  • Copy your configuration file from local host to container path /etc/nanomq.conf: docker cp nanomq.conf nanomq:/etc/nanomq.conf
  • Modify configuration parameters by environment variables, for example:
docker run -d -p 1883:1883 -p 8883:8883 \
           -e NANOMQ_BROKER_URL="nmq-tcp://" \
           -e NANOMQ_TLS_ENABLE=true \
           -e NANOMQ_TLS_URL="tls+nmq-tcp://" \
           --name nanomq emqx/nanomq

The specific parameters are described in the table below

# NanoMQ Environment variables

NANOMQ_BROKER_URLString'nmq-tcp://host:port', 'tls+nmq-tcp://host:port'
NANOMQ_DAEMONBooleanSet nanomq as daemon (default: false).
NANOMQ_NUM_TASKQ_THREADIntegerNumber of taskq threads used, num greater than 0 and less than 256.
NANOMQ_MAX_TASKQ_THREADIntegerMaximum number of taskq threads used, num greater than 0 and less than 256.
NANOMQ_PARALLELLongNumber of parallel.
NANOMQ_PROPERTY_SIZEIntegerMax size for a MQTT user property.
NANOMQ_MSQ_LENIntegerQueue length for resending messages.
NANOMQ_QOS_DURATIONIntegerThe interval of the qos timer.
NANOMQ_ALLOW_ANONYMOUSBooleanAllow anonymous login (default: true).
NANOMQ_WEBSOCKET_ENABLEBooleanEnable websocket listener (default: true).
NANOMQ_WEBSOCKET_URLString'nmq-ws://host:port/path', 'nmq-wss://host:port/path'
NANOMQ_HTTP_SERVER_ENABLEBooleanEnable http server (default: false).
NANOMQ_HTTP_SERVER_PORTIntegerPort for http server (default: 8081).
NANOMQ_HTTP_SERVER_USERNAMEStringHttp server user name for auth.
NANOMQ_HTTP_SERVER_PASSWORDStringHttp server password for auth.
NANOMQ_TLS_ENABLEBooleanEnable TLS connection.
NANOMQ_TLS_CA_CERT_PATHStringPath to the file containing PEM-encoded CA certificates.
NANOMQ_TLS_CERT_PATHStringPath to a file containing the user certificate.
NANOMQ_TLS_KEY_PATHStringPath to the file containing the user's private PEM-encoded key.
NANOMQ_TLS_KEY_PASSWORDStringString containing the user's password. Only used if the private keyfile is password-protected.
NANOMQ_TLS_VERIFY_PEERBooleanVerify peer certificate (default: false).
NANOMQ_TLS_FAIL_IF_NO_PEER_CERTBooleanServer will fail if the client does not have a certificate to send (default: false).
NANOMQ_LOG_TOStringArray of log types,( Use vertical line | to separate multiple types )
Log types: file, console, syslog
NANOMQ_LOG_LEVELStringLog level:trace, debug, info, warn, error, fatal
NANOMQ_LOG_DIRStringThe dir for log files. (if log to file)
NANOMQ_LOG_FILEStringThe log filename. (if log to file)
NANOMQ_LOG_ROTATION_SIZEStringMaximum size of each log file;
Supported Unit: KB | MB | GB;
NANOMQ_LOG_ROTATION_COUNTIntegerMaximum rotation count of log files;
Default: 5
NANOMQ_CONF_PATHStringNanoMQ main config file path (defalt: /etc/nanomq.conf).