Add a new dockerfile and associated files, to build from a source tarball, instead of installing a built and published Alpine APK package.
Signed-off-by: Jonathan Hanson <jonathan@jonathan-hanson.org>pull/1013/head
parent
07d59d20e2
commit
976edc6165
@ -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 <jonathan@jonathan-hanson.org>"
|
||||||
|
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"]
|
@ -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.
|
@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/ash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
exec "$@"
|
Loading…
Reference in New Issue