-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a new dockerfile and associated files, to build from a source tar…
…ball, instead of installing a built and published Alpine APK package. Signed-off-by: Jonathan Hanson <[email protected]>
- Loading branch information
1 parent
07d59d2
commit 976edc6
Showing
3 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <[email protected]>" | ||
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <absolute-path-to-configuration-file>:/mosquitto/config/mosquitto.conf eclipse-mosquitto:<version> | ||
``` | ||
|
||
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:<version> --build-arg VERSION="<version>" . | ||
``` | ||
|
||
## Run | ||
Run a container using the new image: | ||
``` | ||
docker run -it -p 1883:1883 -p 9001:9001 -v <path-to-configuration-file>:/mosquitto/config/mosquitto.conf -v /mosquitto/data -v /mosquitto/log eclipse-mosquitto:<version> | ||
``` | ||
: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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/ash | ||
set -e | ||
|
||
exec "$@" |