Deploy with Docker Compose

Deployment notes

The synced source content for this article currently contains a Redis standalone deployment example. The English page below follows that source so the bilingual route stays aligned.


Environment and system tuning

Prepare the working directory

mkdir -p /data/workspace/install-redis/data && cd /data/workspace/install-redis

System tuning

# temporary tuning
sysctl -w vm.overcommit_memory=1
sysctl -w net.core.somaxconn=1024

# persist the settings
echo "vm.overcommit_memory = 1" >> /etc/sysctl.conf
echo "net.core.somaxconn = 1024" >> /etc/sysctl.conf
sysctl -p

Prepare the Docker Compose file

services:
  redis:
    container_name: redis-standalone
    image: 10.14.0.37/redis/redis-8.4.0:v1
    restart: always
    ports:
      - "3759:6379"
    environment:
      - REDISCLI_AUTH=redis@!QAZxsw2
      - TZ=Asia/Shanghai
    volumes:
      - /data/workspace/install-redis/data:/data
    ulimits:
      nofile:
        soft: 65536
        hard: 65536
    sysctls:
      net.core.somaxconn: 1024
    command:
      - "redis-server"
      - "--requirepass redis@!QAZxsw2"
      - "--appendonly yes"
      - "--appendfsync everysec"
      - "--save 900 1"
      - "--save 300 10"
      - "--maxmemory 2gb"
      - "--maxmemory-policy allkeys-lru"
      - "--timeout 300"
      - "--tcp-keepalive 300"
      - "--databases 16"
      - "--maxclients 10000"
    healthcheck:
      test: ["CMD", "redis-cli", "-a", "redis@!QAZxsw2", "ping"]
      interval: 10s
      timeout: 5s
      retries: 5

Start and verify

Start Redis

docker compose up -d

Verify Redis

docker logs -f redis-standalone

docker exec -it redis-standalone redis-cli
set hello world
get hello

127.0.0.1:6379> config get maxmemory
1) "maxmemory"
2) "2147483648"

The main points worth checking are the password, the max memory limit, and whether AOF plus RDB snapshots are both enabled as expected.