docker创建redis容器时,挂载的redis配置文件密码不生效,解决方案

起因:

镜像: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

配置文件的挂载路径,根据实际调整即可。

相关推荐
虎头金猫20 小时前
4K 视频总卡在公网带宽?用 N1 + OpenList 把网盘播放链路重新理顺
运维·服务器·网络·python·容器·beautifulsoup·pandas
分布式存储与RustFS21 小时前
MinIO 官方 Docker 镜像被移除:依赖它的项目该怎么办
docker·云原生·devops·对象存储·minio·分布式存储
IT大白鼠1 天前
Redis 系列 · 第 01 篇——认知入门:Redis 是什么
redis·nosql
彧azz1 天前
Linux 环境下 Redis 学习总结:数据类型、持久化、锁、事务、主从与缓存问题
linux·redis·笔记·学习·面试
玉&心1 天前
通过Arthas在线诊断K8S中的内存及JVM等使用情况
docker·k8s·arthas
xing-xing1 天前
Docker容器中Nginx站点根目录网页配置访问
nginx·docker
赵文宇(温玉)1 天前
CoreDNS的hosts插件的缺行配置导致k8s集群异常
容器·kubernetes·rancher
guo_wen_qiang1 天前
上传本地镜像到harbor中
docker·容器·持续部署
羑悻的小杀马特1 天前
Dockerfile 全景指南:从入门编写dockerfile到生产环境镜像优化实战,一步步带你从啃透制作指令到镜像制作落地!
docker·dockerfile·镜像制作
BianHuanShiZhe1 天前
docker常见命令
docker