Thursday, 31 July 2025

Build Custom Docker Images with Redis Json and Search Module Support for deploying Bitnami Redis Cluster and Standalone in AKS

 Redis cluster deployed in AKS (kubernetes) is a really useful way to use Redis cache in dotnet projects. To depoy Redis on AKS we can use Redis bitnami cluster or standalone. Cluster mode deployment is only accessible within the kubernetes clsuter, therefore for development environments, to allow local machine access to Redis in an AKS clsuter you need the standalone mode of deployment, which we will discuss in the next post. The bitnnami Redis images are not included with the json module and search module which are useful to store json documents and search them in a Redis setup. In this post let's explore how to include addtional modules in Bitnami Redis to build a custom image so that the Json and Search of Redis available in AKS once deployed.

The expection is to build custom Bitnami Redis images with module support similar to Redis 8 and get them added to Azure Container registry as shown below.


 

To build the custom bitnami Redis cluster docker image, with modules,  we can use the below docker image.

# Stage 1: Extract Redis modules (redisbloom, redisearch, redistimeseries, rejson)
FROM redis:8.0.3 as redismodule-source

# Extract modules
RUN mkdir -p /extracted
RUN cp /usr/local/lib/redis/modules/*.so /extracted/
       
# Stage 2: Build final image based on Bitnami Redis
FROM docker.io/bitnami/redis-cluster:8.0.3-debian-12-r2

USER root

# Create destination path and copy *.so modules from the previous stage
COPY --from=redismodule-source /extracted/ /opt/redis/modules/

# Set proper permissions
RUN chown -R 1001:0 /opt/redis/modules

# Switch back to non-root user
USER 1001

To build the custom bitnami Redsis standalone docker image with modules,  we can use the below docker image.
# Stage 1: Extract modules (redisbloom, redisearch, redistimeseries, rejson)
FROM redis:8.0.3 as redismodule-source

# Extract modules
RUN mkdir -p /extracted
RUN cp /usr/local/lib/redis/modules/*.so /extracted/
       
# Stage 2: Build final image based on Bitnami Redis
FROM docker.io/bitnami/redis:8.0.3-debian-12-r2

USER root

# Create destination path and copy *.so modules from the previous stage
COPY --from=redismodule-source /extracted/ /opt/redis/modules/

# Set proper permissions
RUN chown -R 1001:0 /opt/redis/modules

# Switch back to non-root user
USER 1001

Below you can find simple set of inscrutions on how to build the docker images and push them to Azure container registry. Instructions on how to push images manually to ACR (Azure container registry) can be found here. In the next post let's discuss how to deploy redis cluster with custom image to AKS using bitnami helm charts.


**Cluster Image - bitnami**
`docker.io/bitnami/redis-cluster:8.0.3-debian-12-r2`

**Standalone Image - bitnami**
`docker.io/bitnami/redis:8.0.3-debian-12-r2`

**Modules Copy Image**
To copy modules should use the same redis version image from official redis.
`redis:8.0.2`

## Manual Steps
Avoid using manual steps. Instead use the build `build_redis_images` pipeline to build and push redis image new versions.

**Build Custom Bitnami Image**
`cd <sourcerepo>/iac`
`docker build --no-cache -t px_redis_cluster:dev --progress=plain -f Redis/Redis_Cluster.Dockerfile .`
`docker build --no-cache -t px_redis_standalone:dev --progress=plain -f Redis/Redis_Standalone.Dockerfile .`

**Tag Image**
`docker tag px_redis_cluster:dev chsharedacr.azurecr.io/px/redis/px_redis_cluster:8.0.3-debian-12-r2`
`docker tag px_redis_standalone:dev chsharedacr.azurecr.io/px/redis/px_redis_standalone:8.0.3-debian-12-r2`

**Login to ACR**
`docker login chsharedacr.azurecr.io -u username -p password`

**Push Custom Images to ACR**
`docker push chsharedacr.azurecr.io/px/redis/px_redis_cluster:8.0.3-debian-12-r2`
`docker push chsharedacr.azurecr.io/px/redis/px_redis_standalone:8.0.3-debian-12-r2`

No comments:

Popular Posts