Redis on Docker Compose (LV.1)

ใน session นี้เราจะสร้าง standalone redis โดยใช้ image จาก bitnami เนื่องจาก image ของ bitnami มีการ custom entrypoint script ไว้เยอะ จึงช่วยให้ใช้งานผ่านการ set ENV ต่างๆได้ง่ายกกว่าการใช้ redis image จากของ official โดยตรง

ทำการสร้างไฟล์ docker-compose.yml โดยมี content ดังนี้

services:
  redis:
    image: bitnami/redis:7.4
    environment:
      - ALLOW_EMPTY_PASSWORD=yes
    volumes:
      - redis-data:/bitnami/redis/data
    ports:
      - 6379:6379
  redis-exporter:
    image: oliver006/redis_exporter
    environment:
      - REDIS_ADDR=redis://redis:6379
    ports:
      - 9121:9121
volumes:
  redis-data:

deploy ด้วยการสั่ง compose up

docker compose up -d

จากตัวอย่างจะมีการ deploy redis exporter ด้วย เพื่อให้ tools observability มาอ่านข้อมูลสถานะของ redis ไปได้

Last updated

Was this helpful?