Skip to content

Latest commit

 

History

History
223 lines (195 loc) · 5.5 KB

README.md

File metadata and controls

223 lines (195 loc) · 5.5 KB

Docker for Redis

Redis Docker

Description

This repository made for build simple of Redis with docker

Prerequisite

Quick Start

time ./quick-start.sh

Default Value

Create .env file to define your own value

Variable name Default value Datatype Description
REDIS_VERSION 7.0.7 String Redis image version
REDIS_PORT 6379 number Redis server port
REDIS_PASSWORD password String Redis server password
INSIGHT_VERSION 1.13.1 String Redis insight version
INSIGHT_PORT 8001 String Redis insight port
TIMEZONE 1.13.0 String RedisLabs image version

Setup Redis

Step 1: Add Redis service into your docker-compose.yml

services:
  redis:
    image: redis:${REDIS_VERSION:-7.0.7}
    container_name: redis
    command:
      - "--requirepass ${REDIS_PASSWORD:-password}"
    networks:
      - redis_network
    ports:
      - ${REDIS_PORT:-6379}:6379
    environment:
      TZ: ${TIMEZONE:-"Asia/Bangkok"}
    restart: on-failure

Step 2: Add the network configuration

networks:
  redis_network:
    name: redis_network
    driver: bridge

Step 3: If you want to bind persistence disk you can add volumes in redis services like this

services:
  redis:
    image: redis:${REDIS_VERSION:-7.0.7}
    container_name: redis
    command:
      - "--requirepass ${REDIS_PASSWORD:-password}"
    volumes:
      - redis_server_volume:/data
    networks:
      - redis_network
    ports:
      - ${REDIS_PORT:-6379}:6379
    environment:
      TZ: ${TIMEZONE:-"Asia/Bangkok"}
    restart: on-failure

Please add volume configuration as well

volumes:
  redis_server_volume:
    name: redis_server_volume
    driver: local

Tips

This step is an optional, not required

Step 4: If you want to have something to make sure that your redis have start successfully please add healthcheck in redis

services:
  redis:
    image: redis:${REDIS_VERSION:-7.0.7}
    container_name: redis
    command:
      - "--requirepass ${REDIS_PASSWORD:-password}"
    healthcheck:
      test: [ "CMD", "redis-cli", "--raw", "incr", "ping" ]
      interval: 5s
      timeout: 30s
      retries: 3
    volumes:
      - ./redis.conf:/usr/local/etc/redis/redis.conf
      - redis_server_volume:/data
    networks:
      - redis_network
    ports:
      - ${REDIS_PORT:-6379}:6379
    environment:
      TZ: ${TIMEZONE:-"Asia/Bangkok"}
    restart: on-failure

Tips

This step is an optional, not required

Step 5: Start server

docker-compose up -d

Setup Redis Insight

Step 1: Add Redis Insight service into your docker-compose.yml

  redis-insight:
    image: redislabs/redisinsight:${INSIGHT_VERSION:-1.13.0}
    container_name: redis-insight
    volumes:
      - redis_insight_volume:/db
    networks:
      - redis_network
    ports:
      - ${INSIGHT_PORT:-8001}:8001
    environment:
      TZ: ${TIMEZONE:-"Asia/Bangkok"}
    depends_on:
      - redis
    restart: always

Step 2: Add Redis Insight volume

volumes:
  redis_insight_volume:
    name: redis_insight_volume
    driver: local

Step 3: Start server

docker-compose up -d

Important

Please make sure redis and redis-insight are at the same network group If they're not in same group redis-insight will not found redis server.

Redis Configuration File

Step 1 Download redis.conf template to set advance configuration of Redis from this link Click here

Step 2 Edit Redis service in at volume section in docker-compose.yml like this

services:
  redis:
    image: redis:${REDIS_VERSION:-7.0.7}
    container_name: redis
    volumes:
      - ./redis.conf:/usr/local/etc/redis/redis.conf
      - redis_server_volume:/data
    networks:
      - redis_network
    ports:
      - ${REDIS_PORT:-6379}:6379
    environment:
      TZ: ${TIMEZONE:-"Asia/Bangkok"}
    restart: on-failure

Tips

If you have redis.conf you can move REDIS_ARGS environment into redis.conf instead

Example

requirepass <your password>

Step 4: Start server

docker-compose up -d

Redis CLI

Run docker command to access redis server

docker exec -it redis redis-cli

After access to redis-cli you should be see interface like this

127.0.0.1:6379>

And then before do anything you must login first.

AUTH [username] [password]

Example

AUTH default password

Reference

Docker Hub
Redis
Redis Stack
RedisLabs
Configuration Example
Configuration Doc

Contributor

Harin3Bone