Skip to content

Instantly share code, notes, and snippets.

@misTrasteos
Created July 25, 2021 11:22
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save misTrasteos/edd6f476eb67b9d342888c4de2f32a01 to your computer and use it in GitHub Desktop.
Save misTrasteos/edd6f476eb67b9d342888c4de2f32a01 to your computer and use it in GitHub Desktop.
Redis distroless Docker image

This is an PoC about building a distroless Redis Docker image.

How to build the image

docker build -t redis:distroless --build-arg REDIS_VERSION=5.0.9 --build-arg GCC_VERSION=9 .

Notes about compilers As fas as today, July 25th 2021

  • Use gcc:9 to compile Redis 5.X
  • Use gcc:10 or higher to compile Redis 6.X

Image contents If you dive the image. These are the only contents

├── bin │ └── redis-server └── etc └── redis └── redis.conf

Image size

docker image ls | grep -i redis
redis          distroless   f2df04acb352   14 minutes ago   13.5MB
redis          alpine       eb705d309426   47 hours ago     32.3MB

Run the image

docker run redis:distroless
1:C 25 Jul 2021 11:17:56.935 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:C 25 Jul 2021 11:17:56.935 # Redis version=5.0.9, bits=64, commit=00000000, modified=0, pid=1, just started
1:C 25 Jul 2021 11:17:56.935 # Configuration loaded
                _._
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 5.0.9 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 1
  `-._    `-._  `-./  _.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |           http://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'
              `-.__.-'

1:M 25 Jul 2021 11:17:56.936 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
1:M 25 Jul 2021 11:17:56.936 # Server initialized
1:M 25 Jul 2021 11:17:56.936 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
1:M 25 Jul 2021 11:17:56.937 * Ready to accept connections
ARG GCC_VERSION=11
FROM gcc:${GCC_VERSION} AS builder
ARG REDIS_VERSION=stable
# from https://redis.io/topics/quickstart
RUN wget https://download.redis.io/releases/redis-${REDIS_VERSION}.tar.gz && \
tar xvzf redis-${REDIS_VERSION}.tar.gz && \
cd redis-${REDIS_VERSION} && \
make CFLAGS="-static" EXEEXT="-static" LDFLAGS="-static"
RUN mkdir -p /output/bin
WORKDIR /output/bin
RUN cp /redis-${REDIS_VERSION}/src/redis-server .
# Choose whatever binary that suits you, and change accordingly the ENTRYPOINT
#RUN cp /redis-${REDIS_VERSION}/src/redis-sentinel .
#RUN cp /redis-${REDIS_VERSION}/src/redis-cli .
#RUN cp /redis-${REDIS_VERSION}/src/redis-benchmark .
#RUN cp /redis-${REDIS_VERSION}/src/redis-check-aof .
#RUN cp /redis-${REDIS_VERSION}/src/redis-check-rdb .
RUN mkdir -p /output/conf
WORKDIR /output/conf
RUN cp /redis-${REDIS_VERSION}/redis.conf .
FROM scratch
COPY --from=builder /output/conf/redis.conf /etc/redis/redis.conf
COPY --from=builder /output/bin/* /bin/
ENTRYPOINT ["/bin/redis-server", "/etc/redis/redis.conf"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment