Redis, sidekiq and docker-compose using AWS elasticache(clusters)

Viewed 89

The main problem I have got when I started this project is to assign to sidekiq the redis connection and to use elasticache redis cluster inside redis. this is my docker-compose file:

version: "3.3"
services:
  db:
    image: postgres:12.9-alpine
    ports:
      - "5432:5432"
    volumes:
      - db_data_postgres:/var/lib/postgresql/data
    networks:
      appnet:
    ipv4_address: 172.20.0.3

  redis:
    image: redis:latest
    restart: always
    ports:
      - '6379:6379'
    command: bash -c "redis-server" # what should go here?
    networks:
      appnet:
    ipv4_address: 172.20.0.4

  app:
    build:
      context: .
    volumes:
      - .:/app
      - gem_cache:/usr/local/bundle/gems
      - node_modules:/app/node_modules
    depends_on:
      - db
      - worker_sidekiq
    links:
      - db
    ports:
      - "8000:8000"
    env_file:
      - .env
    environment:
      - REDIS_URL=redis://redis:6379
    command: bash -c "rm -f tmp/pids/server.pid && RAILS_ENV=development bin/rails s -b '0.0.0.0' -p 8000"
    networks:
      appnet:
    ipv4_address: 172.20.0.5

  worker_sidekiq:
    build: .
    image: app
    command: bash -c "bundle exec sidekiq"
    volumes:
      - .:/app
      - gem_cache:/usr/local/bundle/gems
      - node_modules:/app/node_modules
    depends_on:
      - redis
    environment:
      - REDIS_URL=redis://redis:6379
    networks:
      appnet:
        ipv4_address: 172.20.0.6

networks:
  appnet:
    ipam:
      config:
    - subnet: 172.20.0.0/16

volumes:
  gem_cache:
  db_data_postgres:
  node_modules:

I've tried command: redis-cli -h *.*.use1.cache.amazonaws.com -p 6379 but I got errors on start. I have tried to figured it out for a while and i don't know how to link the AWS Redis Cluster in my docker-compose file. Any ideeas?

1 Answers
Related