diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..9414382 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..fff6e0a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,38 @@ +# build target, used for building the binary, providing shared libraries and could be used as a development env +FROM debian:bullseye-slim as build + +# install build dependencies +RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y install g++ make cmake libssl-dev + +# create flashmq user and group for runtime image below +RUN useradd --system --shell /bin/false --user-group --no-log-init flashmq + +WORKDIR /usr/src/app +COPY . . +RUN ./build.sh + + +# from scratch image is empty +FROM scratch as run + +# set the user/group to flashmq and copy the passwd/group files from build to make that work +USER flashmq:flashmq +COPY --from=build /etc/passwd /etc/passwd +COPY --from=build /etc/group /etc/group + +# copy in the shared libaries in use discovered using ldd on release binary +COPY --from=build /lib/x86_64-linux-gnu/libpthread.so.0 /lib/x86_64-linux-gnu/libpthread.so.0 +COPY --from=build /lib/x86_64-linux-gnu/libdl.so.2 /lib/x86_64-linux-gnu/libdl.so.2 +COPY --from=build /usr/lib/x86_64-linux-gnu/libssl.so.1.1 /usr/lib/x86_64-linux-gnu/libssl.so.1.1 +COPY --from=build /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1 /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1 +COPY --from=build /usr/lib/x86_64-linux-gnu/libstdc++.so.6 /usr/lib/x86_64-linux-gnu/libstdc++.so.6 +COPY --from=build /lib/x86_64-linux-gnu/libgcc_s.so.1 /lib/x86_64-linux-gnu/libgcc_s.so.1 +COPY --from=build /lib/x86_64-linux-gnu/libc.so.6 /lib/x86_64-linux-gnu/libc.so.6 +COPY --from=build /lib64/ld-linux-x86-64.so.2 /lib64/ld-linux-x86-64.so.2 +COPY --from=build /lib/x86_64-linux-gnu/libm.so.6 /lib/x86_64-linux-gnu/libm.so.6 + +# copy in the FlashMQ binary itself +COPY --from=build /usr/src/app/FlashMQBuildRelease/FlashMQ /bin/FlashMQ + +EXPOSE 1883 +CMD ["/bin/FlashMQ"] diff --git a/README.md b/README.md index 46a0f83..defb71a 100644 --- a/README.md +++ b/README.md @@ -5,4 +5,21 @@ FlashMQ is a light-weight MQTT broker/server, designed to take good advantage of Build with buid.sh. +## Docker + +Official Docker images aren't available yet, but building your own Docker image can be done with the provided Dockerfile. + +``` +# build flashmq docker image +docker build . -t halfgaar/flashmq + +# run using docker (with, as an example, a place for a config file (default +# name flashmq.conf). Create extra volumes as you need, for the persistence DB +# file, logs, password files, auth plugin, etc. +docker run -p 1883:1883 -v /srv/flashmq/etc/:/etc/flashmq halfgaar/flashmq + +# for development you can target the build stage to get an image you can use for development +docker build . --target=build +``` + See [www.flashmq.org](https://www.flashmq.org)