Skip to content

Commit

Permalink
Add a new dockerfile and associated files, to build from a source tar…
Browse files Browse the repository at this point in the history
…ball, instead of installing a built and published Alpine APK package.

Signed-off-by: Jonathan Hanson <[email protected]>
  • Loading branch information
triplepoint authored and ralight committed Oct 23, 2018
1 parent 07d59d2 commit 976edc6
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 0 deletions.
70 changes: 70 additions & 0 deletions docker/from_dist/Dockerfile
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"]
47 changes: 47 additions & 0 deletions docker/from_dist/README.md
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.
4 changes: 4 additions & 0 deletions docker/from_dist/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/ash
set -e

exec "$@"

0 comments on commit 976edc6

Please sign in to comment.