# Builder image FROM golang:1.12-alpine as builder ENV PATH=/src/go/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin RUN install -d /src && \ install -d /src/mosquitto && \ install -d /src/mosquitto-auth RUN apk add --no-cache \ curl \ c-ares-dev \ gcc \ git \ g++ \ libwebsockets-dev \ make \ musl-dev \ openssl-dev \ sed \ tar RUN curl -s https://mosquitto.org/files/source/mosquitto-1.6.2.tar.gz | tar --strip-components=1 -C /src/mosquitto -xzf - RUN make -C /src/mosquitto \ WITH_MEMORY_TRACKING=no \ WITH_WEBSOCKETS=yes \ WITH_SRV=yes \ WITH_TLS_PSK=no \ WITH_ADNS=no \ prefix=/usr \ binary && \ make -C /src/mosquitto \ prefix=/usr \ DESTDIR="/install" \ install RUN curl -s -L https://github.com/iegomez/mosquitto-go-auth/archive/0.3.0.tar.gz | tar --strip-components=1 -C /src/mosquitto-auth -xzf - RUN cd /src/mosquitto-auth && \ CGO_CFLAGS="-I/install/usr/include -fPIC" \ CGO_LDFLAGS="-shared" \ make # not used: #CGO_ENABLED="1" \ #GOOS="linux" \ # Final image FROM alpine LABEL description="Eclipse Mosquitto MQTT Broker" ENV USER=mosquitto \ UID=1000 \ GID=1000 RUN addgroup --gid "$GID" "$USER" \ && adduser \ --disabled-password \ --gecos "" \ --home "/mosquitto" \ --ingroup "$USER" \ --no-create-home \ --uid "$UID" \ "$USER" RUN install -d -o mosquitto /mosquitto && \ install -d -o mosquitto /mosquitto/config && \ install -d -o mosquitto /mosquitto/data && \ install -d -o mosquitto /mosquitto/log RUN apk add --no-cache \ c-ares \ libwebsockets \ musl COPY --from=builder /install / COPY --from=builder /src/mosquitto-auth/go-auth.so /mosquitto/ VOLUME /mosquitto/config /mosquitto/data /mosquitto/log WORKDIR /mosquitto USER mosquitto EXPOSE 1883 8883 COPY mosquitto.conf /mosquitto/ ENTRYPOINT ["mosquitto"] CMD ["-c", "/mosquitto/mosquitto.conf"]