简体   繁体   English

如何在 docker-compose 中使用 redis 用户名和密码?

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

Currently I have the below service configured in my docker-compose which works correct with redis password.目前我在我的docker-compose中配置了以下服务,该服务适用于 redis 密码。 However, I would like to use also redis username together with password.但是,我也想使用 redis 用户名和密码。 Is there any similar command to requirepass or something else to enable username ?是否有任何类似的命令来requirepass或其他启用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

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然后将以下内容添加到您的 docker 撰写文件中

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如果您需要更细粒度的控制,您可能需要查看那里注释的 ACL 行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM