Dockerfile.stunnel 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. ###############################################################################
  2. # Build stage – compile OpenSSL 1.0.2u and stunnel 5.75
  3. ###############################################################################
  4. FROM debian:12.11-slim AS build
  5. ARG OPENSSL_VERSION=1.0.2u
  6. ARG OPENSSL_TAG=OpenSSL_1_0_2u
  7. ARG STUNNEL_VERSION=5.76
  8. ARG OPENSSL_URL=https://github.com/openssl/openssl/releases/download/${OPENSSL_TAG}/openssl-${OPENSSL_VERSION}.tar.gz
  9. ARG STUNNEL_URL=https://www.stunnel.org/archive/5.x/stunnel-${STUNNEL_VERSION}.tar.gz
  10. # Build prerequisites
  11. RUN apt-get update && \
  12. apt-get install -y --no-install-recommends \
  13. build-essential \
  14. ca-certificates \
  15. wget \
  16. perl \
  17. zlib1g-dev \
  18. pkg-config && \
  19. rm -rf /var/lib/apt/lists/*
  20. WORKDIR /usr/src
  21. # ---------- OpenSSL ----------------------------------------------------------
  22. RUN wget -qO openssl.tar.gz "${OPENSSL_URL}" && \
  23. tar xzf openssl.tar.gz && \
  24. cd openssl-${OPENSSL_VERSION} && \
  25. ./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl shared zlib && \
  26. make -j"$(nproc)" && \
  27. make install_sw
  28. # ---------- stunnel ----------------------------------------------------------
  29. RUN wget -qO stunnel.tar.gz "${STUNNEL_URL}" && \
  30. tar xzf stunnel.tar.gz && \
  31. cd stunnel-${STUNNEL_VERSION} && \
  32. ./configure \
  33. --with-ssl=/usr/local/openssl \
  34. --prefix=/usr/local \
  35. --sysconfdir=/etc \
  36. --disable-libwrap && \
  37. make -j"$(nproc)" && \
  38. make install
  39. ###############################################################################
  40. # Runtime stage – only what we need to run stunnel
  41. ###############################################################################
  42. FROM debian:bookworm-slim AS runtime
  43. COPY --from=build /usr/local/openssl /usr/local/openssl
  44. COPY --from=build /usr/local/bin/stunnel /usr/local/bin/
  45. COPY --from=build /usr/local/lib /usr/local/lib
  46. # Make sure the custom OpenSSL is preferred at runtime
  47. ENV LD_LIBRARY_PATH="/usr/local/openssl/lib"
  48. # Directory to hold the user‑supplied stunnel.conf
  49. RUN mkdir -p /etc/stunnel
  50. WORKDIR /etc/stunnel
  51. EXPOSE 443 1088
  52. ENTRYPOINT ["stunnel"]
  53. # You can pass the config file name as CMD or at `docker run` time, e.g.:
  54. # CMD ["stunnel.conf"]