起因:
镜像:redis:7.2.4
创建容器之后设置的密码未生效,还是无密码登录状态。
docker-compose脚本:
services:
redis:
image: redis:7.2.4
container_name: redis
restart: always
ports:
- 6379:6379
volumes:
- ./redis/conf:/usr/local/etc/redis
- /etc/localtime:/etc/localtime:ro
networks:
- your-network
networks:
your-network:
external: true
redis.conf内容(简易配置):
#bind 0.0.0.0
protected-mode no
daemonize no
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 0
loglevel notice
logfile ""
databases 12
save ""
#save 900 1
#save 300 10
#save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir ./
requirepass abc123456
解决方法一:手动解决
1.进入redis容器,命令:docker exec -it redis bash 。红色redis为容器名称
2.输入命令:redis-cli config set requirepass abc123456 红色为设置的密码。
3.验证登录1:redis-cli -a abc123456
验证方式2(推荐):redis-cli 回车,进入控制台,在输入:AUTH abc23456
解决方法二:添加启动项,重新加载配置文件。
services:
redis:
image: redis:7.2.4
container_name: redis
restart: always
ports:
- 6379:6379
volumes:
- ./conf/redis.conf:/usr/local/etc/redis/redis.conf
- /etc/localtime:/etc/localtime:ro
command: ["redis-server", "/usr/local/etc/redis/redis.conf"]
networks:
- 1panel-network
networks:
1panel-network:
external: true
commond作用是在容器启动后重新加载redis.conf
配置文件的挂载路径,根据实际调整即可。