Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use redis username with password in docker-compose?

Tags:

docker

redis

Currently I have the below service configured in my docker-compose which works correct with redis password. However, I would like to use also redis username together with password. Is there any similar command to requirepass or something else to enable username?

version: '3.9'
volumes:
  redis_data: {}
networks:
  ee-net:
    driver: bridge
services:
  redis:
    image: 'redis:latest'
    container_name: redis
    hostname: redis
    networks:
      - ee-net
    ports:
      - '6379:6379'
    command: '--requirepass redisPassword'
    volumes:
      - redis_data:/data
like image 342
Hayk Avatar asked Aug 30 '25 17:08

Hayk


1 Answers

You can specify a config file

$ cat redis.conf
requirepass password
#aclfile /etc/redis/users.acl

Then add the following to your docker compose file

version: '3'
services:
  redis:
    image: redis:latest
    command: ["redis-server", "/etc/redis/redis.conf"]
    volumes:
      - ./redis.conf:/etc/redis/redis.conf
    ports:
      - "6379:6379"

Then you will get the password requirements

redis-cli
127.0.0.1:6379> ping
(error) NOAUTH Authentication required.
127.0.0.1:6379> AUTH password
OK
127.0.0.1:6379> ping
PONG

You may want to look into the ACLs line commented out there if you require more fine grained control

like image 144
namizaru Avatar answered Sep 02 '25 13:09

namizaru