diff --git a/docker/from_dist/Dockerfile b/docker/from_dist/Dockerfile new file mode 100644 index 00000000..3b36963d --- /dev/null +++ b/docker/from_dist/Dockerfile @@ -0,0 +1,70 @@ +FROM alpine:latest AS build + +# A released dist version, like "1.2.3" +ARG VERSION +RUN test -n "${VERSION}" + +RUN apk --no-cache add \ + build-base \ + libressl-dev \ + c-ares-dev \ + curl \ + util-linux-dev \ + libwebsockets-dev \ + libxslt \ + python2 + +# This build procedure is based on: +# https://github.com/alpinelinux/aports/blob/master/main/mosquitto/APKBUILD +# +# If this step fails, double check the version build-arg and make sure its +# a valid published tarball at https://mosquitto.org/files/source/ +RUN mkdir -p /build /install && \ + curl -SL https://mosquitto.org/files/source/mosquitto-${VERSION}.tar.gz \ + | tar --strip=1 -xzC /build && \ + make -C /build \ + WITH_MEMORY_TRACKING=no \ + WITH_WEBSOCKETS=yes \ + WITH_SRV=yes \ + WITH_TLS_PSK=no \ + WITH_ADNS=no \ + prefix=/usr \ + binary && \ + make -C /build \ + prefix=/usr \ + DESTDIR="/install" \ + install && \ + mv /install/etc/mosquitto/mosquitto.conf.example /install/etc/mosquitto/mosquitto.conf && \ + sed -i -e 's/#log_dest stderr/log_dest syslog/' /install/etc/mosquitto/mosquitto.conf + + +# Single-layer image for the mosquitto distribution +FROM alpine:latest +LABEL maintainer="Jonathan Hanson " +LABEL description="Eclipse Mosquitto MQTT Broker" + +# Install the run-time dependencies +RUN apk --no-cache add \ + busybox \ + libcrypto1.0 \ + libssl1.0 \ + libuuid \ + libwebsockets \ + musl + +# Copy over the built install from the earlier image layer +COPY --from=build /install / + +# Set up the mosquitto directories and the mosquitto user +RUN addgroup -S mosquitto 2>/dev/null && \ + adduser -S -D -H -h /var/empty -s /sbin/nologin -G mosquitto -g mosquitto mosquitto 2>/dev/null && \ + mkdir -p /mosquitto/config /mosquitto/data /mosquitto/log && \ + cp /etc/mosquitto/mosquitto.conf /mosquitto/config && \ + chown -R mosquitto:mosquitto /mosquitto + +VOLUME ["/mosquitto/config", "/mosquitto/data", "/mosquitto/log"] + +# Set up the entry point script and default command +COPY docker-entrypoint.sh / +ENTRYPOINT ["/docker-entrypoint.sh"] +CMD ["/usr/sbin/mosquitto", "-c", "/mosquitto/config/mosquitto.conf"] diff --git a/docker/from_dist/README.md b/docker/from_dist/README.md new file mode 100644 index 00000000..421cb91d --- /dev/null +++ b/docker/from_dist/README.md @@ -0,0 +1,47 @@ +# Eclipse Mosquitto Docker Image +Containers built with this Dockerfile build as source from published tarballs. + +## Mount Points +Three docker volumes have been created in the image to be used for configuration, persistent storage and logs. +``` +/mosquitto/config +/mosquitto/data +/mosquitto/log +``` + +## Configuration +When creating a container from the image, the default configuration values are used. +To use a custom configuration file, mount a **local** configuration file to `/mosquitto/config/mosquitto.conf` +``` +docker run -it -p 1883:1883 -p 9001:9001 -v :/mosquitto/config/mosquitto.conf eclipse-mosquitto: +``` + +Configuration can be changed to: + +* persist data to `/mosquitto/data` +* log to `/mosquitto/log/mosquitto.log` + +i.e. add the following to `mosquitto.conf`: +``` +persistence true +persistence_location /mosquitto/data/ + +log_dest file /mosquitto/log/mosquitto.log +``` + +**Note**: For any volume used, the data will be persistent between containers. + +## Build +Build and tag the docker image for a specific version: +``` +docker build -t eclipse-mosquitto: --build-arg VERSION="" . +``` + +## Run +Run a container using the new image: +``` +docker run -it -p 1883:1883 -p 9001:9001 -v :/mosquitto/config/mosquitto.conf -v /mosquitto/data -v /mosquitto/log eclipse-mosquitto: +``` +:boom: if the mosquitto configuration (mosquitto.conf) was modified +to use non-default ports, the docker run command will need to be updated +to expose the ports that have been configured. diff --git a/docker/from_dist/docker-entrypoint.sh b/docker/from_dist/docker-entrypoint.sh new file mode 100755 index 00000000..b381ac57 --- /dev/null +++ b/docker/from_dist/docker-entrypoint.sh @@ -0,0 +1,4 @@ +#!/bin/ash +set -e + +exec "$@"