Tag Archives: lightsail

Setting up Redis Stack on AWS Lightsail using Docker

I’ve been using Bitnami’s redis server on the default NodeJS instance on Lightsail but unfortunately, it’s not the full stack so it’s missing GEO, JSON and full text search support which is a bit of a bummer. So, to solve that problem I decided to see if I could setup Redis Stack using docker on a Lightsail instance. I decided not to use LS container support as I can get an 8GB instance for $40/month, vs. a similar container instance at $100/month.

Redis Stack Cloud on us-west-2 for 5GB of RAM runs $105/month (as of April ’23) without HA.

To start, I created a Debian OS only instance and installed docker:

Install Docker Engine on Debian

Start docker at boot:

$ sudo systemctl enable docker.service
$ sudo systemctl enable containerd.service

And install docker-compose:

$ sudo apt install docker-compose

Next, install both make and gcc to build redis-cli:

Debian Linux Install GNU GCC Compiler

Basically, use this:

$ sudo apt-get update
$ sudo apt-get install build-essential

Next, I wanted just redis-cli installed so here are the steps for building redis-cli:

Install just redis-cli on Ubuntu, Debian

$ cd /tmp
$ wget http://download.redis.io/redis-stable.tar.gz
$ tar xvzf redis-stable.tar.gz
$ cd redis-stable
$ make
$ cp src/redis-cli /usr/local/bin/
$ chmod 755 /usr/local/bin/redis-cli

BUT, I ran into this error running make:

Error jemalloc/jemalloc.h: No such file or directory when making Redis

…and fixed it following the instructions:

$ cd /tmp/redis-stable
$ make distclean
$ make

Next, I copied my docker-compose.yaml (see below) and redis.conf files to the instance at:

~/conf/redis/redis.conf
~/docker-compose.yaml

Here’s my docker-compose.yaml

version: '3'
services:
  redis:
    restart: always
    container_name: redis-stack
    command: redis-server /usr/local/etc/redis/redis.conf
    environment:
      - REDIS_AOF_ENABLED=no
    image: redis/redis-stack-server:latest
    ports:
      - '6379:6379'
    volumes:
      - ./redis-data:/data
      - ./conf/redis/redis.conf:/usr/local/etc/redis/redis.conf

I’m not going to replicate my redis.conf file as it’s too long but I set “requirepass” with the password I’m using which is picked up by redis-server.

For redis-cli you’ll want to set REDISCLI_AUTH variable in /etc/environment:

REDISCLI_AUTH=<password>

Next, start docker and run docker-compose:

$ sudo systemctl start docker
$ sudo docker-compose up -d

Test using the CLI:

$ export REDISCLI_AUTH=<password>
$ redis-cli
127.0.0.1:6379> ping
PONG

Update May 8, 2023
I found that the various modules included as part of Redis Stack were not loading due to my overriding redis.conf so I had to add the following to my conf file:

loadmodule /opt/redis-stack/lib/rejson.so
loadmodule /opt/redis-stack/lib/redisgraph.so
loadmodule /opt/redis-stack/lib/redistimeseries.so
loadmodule /opt/redis-stack/lib/redisbloom.so
loadmodule /opt/redis-stack/lib/redisearch.so

Enjoy.