Dockerfile 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. FROM alpine:3.14@sha256:06b5d462c92fc39303e6363c65e074559f8d6b1363250027ed5053557e3398c5
  2. # add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added
  3. RUN addgroup -S -g 1000 redis && adduser -S -G redis -u 999 redis
  4. # alpine already has a gid 999, so we'll use the next id
  5. RUN apk add --no-cache \
  6. # grab su-exec for easy step-down from root
  7. 'su-exec>=0.2' \
  8. # add tzdata for https://github.com/docker-library/redis/issues/138
  9. tzdata
  10. ENV REDIS_VERSION 6.2.6
  11. ENV REDIS_DOWNLOAD_URL http://download.redis.io/releases/redis-6.2.6.tar.gz
  12. ENV REDIS_DOWNLOAD_SHA 5b2b8b7a50111ef395bf1c1d5be11e6e167ac018125055daa8b5c2317ae131ab
  13. RUN set -eux; \
  14. \
  15. apk add --no-cache --virtual .build-deps \
  16. coreutils \
  17. dpkg-dev dpkg \
  18. gcc \
  19. linux-headers \
  20. make \
  21. musl-dev \
  22. openssl-dev \
  23. # install real "wget" to avoid:
  24. # + wget -O redis.tar.gz https://download.redis.io/releases/redis-6.0.6.tar.gz
  25. # Connecting to download.redis.io (45.60.121.1:80)
  26. # wget: bad header line: XxhODalH: btu; path=/; Max-Age=900
  27. wget \
  28. ; \
  29. \
  30. wget -O redis.tar.gz "$REDIS_DOWNLOAD_URL"; \
  31. echo "$REDIS_DOWNLOAD_SHA *redis.tar.gz" | sha256sum -c -; \
  32. mkdir -p /usr/src/redis; \
  33. tar -xzf redis.tar.gz -C /usr/src/redis --strip-components=1; \
  34. rm redis.tar.gz; \
  35. \
  36. # disable Redis protected mode [1] as it is unnecessary in context of Docker
  37. # (ports are not automatically exposed when running inside Docker, but rather explicitly by specifying -p / -P)
  38. # [1]: https://github.com/redis/redis/commit/edd4d555df57dc84265fdfb4ef59a4678832f6da
  39. grep -E '^ *createBoolConfig[(]"protected-mode",.*, *1 *,.*[)],$' /usr/src/redis/src/config.c; \
  40. sed -ri 's!^( *createBoolConfig[(]"protected-mode",.*, *)1( *,.*[)],)$!\10\2!' /usr/src/redis/src/config.c; \
  41. grep -E '^ *createBoolConfig[(]"protected-mode",.*, *0 *,.*[)],$' /usr/src/redis/src/config.c; \
  42. # for future reference, we modify this directly in the source instead of just supplying a default configuration flag because apparently "if you specify any argument to redis-server, [it assumes] you are going to specify everything"
  43. # see also https://github.com/docker-library/redis/issues/4#issuecomment-50780840
  44. # (more exactly, this makes sure the default behavior of "save on SIGTERM" stays functional by default)
  45. \
  46. # https://github.com/jemalloc/jemalloc/issues/467 -- we need to patch the "./configure" for the bundled jemalloc to match how Debian compiles, for compatibility
  47. # (also, we do cross-builds, so we need to embed the appropriate "--build=xxx" values to that "./configure" invocation)
  48. gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \
  49. extraJemallocConfigureFlags="--build=$gnuArch"; \
  50. # https://salsa.debian.org/debian/jemalloc/-/blob/c0a88c37a551be7d12e4863435365c9a6a51525f/debian/rules#L8-23
  51. dpkgArch="$(dpkg --print-architecture)"; \
  52. case "${dpkgArch##*-}" in \
  53. amd64 | i386 | x32) extraJemallocConfigureFlags="$extraJemallocConfigureFlags --with-lg-page=12" ;; \
  54. *) extraJemallocConfigureFlags="$extraJemallocConfigureFlags --with-lg-page=16" ;; \
  55. esac; \
  56. extraJemallocConfigureFlags="$extraJemallocConfigureFlags --with-lg-hugepage=21"; \
  57. grep -F 'cd jemalloc && ./configure ' /usr/src/redis/deps/Makefile; \
  58. sed -ri 's!cd jemalloc && ./configure !&'"$extraJemallocConfigureFlags"' !' /usr/src/redis/deps/Makefile; \
  59. grep -F "cd jemalloc && ./configure $extraJemallocConfigureFlags " /usr/src/redis/deps/Makefile; \
  60. \
  61. export BUILD_TLS=yes; \
  62. make -C /usr/src/redis -j "$(nproc)" all; \
  63. make -C /usr/src/redis install; \
  64. \
  65. # TODO https://github.com/redis/redis/pull/3494 (deduplicate "redis-server" copies)
  66. serverMd5="$(md5sum /usr/local/bin/redis-server | cut -d' ' -f1)"; export serverMd5; \
  67. find /usr/local/bin/redis* -maxdepth 0 \
  68. -type f -not -name redis-server \
  69. -exec sh -eux -c ' \
  70. md5="$(md5sum "$1" | cut -d" " -f1)"; \
  71. test "$md5" = "$serverMd5"; \
  72. ' -- '{}' ';' \
  73. -exec ln -svfT 'redis-server' '{}' ';' \
  74. ; \
  75. \
  76. rm -r /usr/src/redis; \
  77. \
  78. runDeps="$( \
  79. scanelf --needed --nobanner --format '%n#p' --recursive /usr/local \
  80. | tr ',' '\n' \
  81. | sort -u \
  82. | awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
  83. )"; \
  84. apk add --no-network --virtual .redis-rundeps $runDeps; \
  85. apk del --no-network .build-deps; \
  86. \
  87. redis-cli --version; \
  88. redis-server --version
  89. RUN mkdir /data && chown redis:redis /data
  90. VOLUME /data
  91. WORKDIR /data
  92. COPY . .
  93. RUN chmod 777 /data/third_party/redis/docker-entrypoint.sh
  94. RUN cp /data/third_party/redis/docker-entrypoint.sh /usr/local/bin/
  95. ENTRYPOINT ["docker-entrypoint.sh"]
  96. EXPOSE 6379
  97. CMD ["redis-server"]
  98. #CMD nc -lkp 2000 0.0.0.0