目前,我在我的配置中配置了以下服务docker-compose,它可以使用 redis 密码正确工作。但是,我还想使用 redis 用户名和密码。是否有任何类似的命令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
Run Code Online (Sandbox Code Playgroud)
小智 15
您可以指定一个配置文件
$ cat redis.conf
requirepass password
#aclfile /etc/redis/users.acl
Run Code Online (Sandbox Code Playgroud)
然后将以下内容添加到您的 docker compose 文件中
version: '3'
services:
redis:
image: redis:latest
command: ["redis-server", "/etc/redis/redis.conf"]
volumes:
- ./redis.conf:/etc/redis/redis.conf
ports:
- "6379:6379"
Run Code Online (Sandbox Code Playgroud)
然后你会得到密码要求
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
Run Code Online (Sandbox Code Playgroud)
如果您需要更细粒度的控制,您可能需要查看注释掉的 ACL 行
exa*_*cae 13
将用户作为环境标志传递对我来说就足够了。这是使用redis-stack 的示例。
redis:
image: redis/redis-stack:6.2.6-v7
restart: always
environment:
REDIS_ARGS: "--requirepass password --user username on >password ~* allcommands --user default off nopass nocommands"
ports:
- "8001:8001"
- "6379:6379"
volumes:
- ./data/redis:/data
Run Code Online (Sandbox Code Playgroud)
这将禁用“默认”redis 用户并激活名为“username”且密码为“password”的用户。ACL语法 Redis 文档详细介绍了
上面的示例也适用于redis-stack-server映像。这个想法是利用Redis 配置文档中的这一部分:
通过命令行传递的参数格式与redis.conf文件中使用的格式完全相同,只是关键字前缀为--。
| 归档时间: |
|
| 查看次数: |
58143 次 |
| 最近记录: |