diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..33d5dd9b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,41 @@ +FROM alpine:latest as builder + +# We will build docker image in 2 stages. +# This is 1st stage and we will use it to build i2pd executable. + +# 1. install deps +RUN apk add --no-cache build-base libtool boost-dev openssl-dev zlib-dev + +# 2. copy sources +WORKDIR /src +COPY . /src + +# 3. build +RUN make -j$(nproc) +# 4. strip executable +RUN strip --strip-all i2pd + +FROM alpine:latest + +# This is 2nd stage and it will be used to run i2pd. + +# 1. create user to run i2pd from it +RUN mkdir /var/lib/i2pd && adduser -S -h /var/lib/i2pd i2pd \ + && chown -R i2pd:nobody /var/lib/i2pd + +# 2. install required libraries to run i2pd +RUN apk add --no-cache boost-system boost-date_time boost-filesystem \ + boost-program_options libstdc++ libgcc openssl zlib su-exec + +# 3. copy i2pd binary from 1st stage +COPY --from=builder /src/i2pd /usr/local/bin/ + +# 4. copy entrypoint.sh +COPY build/docker/entrypoint.sh /entrypoint.sh +RUN chmod a+x /entrypoint.sh + +VOLUME [ "/var/lib/i2pd" ] + +EXPOSE 7070 4444 4447 7656 2827 7654 7650 + +ENTRYPOINT [ "/entrypoint.sh" ] diff --git a/build/docker/entrypoint.sh b/build/docker/entrypoint.sh new file mode 100644 index 00000000..f9710ba5 --- /dev/null +++ b/build/docker/entrypoint.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +ARGS="" +if [ "${ENABLE_IPV6}" != "" ]; then + ARGS="${ARGS} –ipv6" +fi + +if [ "${LOGLEVEL}" != "" ]; then + ARGS="${ARGS} –loglevel=${LOGLEVEL}" +fi + +if [ "${ENABLE_AUTH}" != "" ]; then + ARGS="${ARGS} –http.auth" +fi + + +# To make ports exposeable +DEFAULT_ARGS=" –http.address=0.0.0.0 –httpproxy.address=0.0.0.0 -socksproxy.address=0.0.0.0 –sam.address=0.0.0.0 –bob.address=0.0.0.0 –i2cp.address=0.0.0.0 –i2pcontrol.port=0.0.0.0 –upnp.enabled=false -service " + +chown -R i2pd:nobody /var/lib/i2pd && chmod u+rw /var/lib/i2pd + +su-exec i2pd i2pd $DEFAULT_ARGS $ARGS + +