• Docker 搭建Redis 踩坑


    在使用 Docker 搭建 Redis 的过程中,产生了刻板效应,导致的搭建时间的延长,做个小记录,提醒自己!

    创建属于自己的 Redis

    新建一个 Redis 的 Dockerfile , Redis 的版本没有选择默认为 lastest

    FROM redis
    COPY redis.conf /usr/local/etc/redis/redis.conf
    CMD [ "redis-server", "/usr/local/etc/redis/redis.conf" ]
    
    • 1
    • 2
    • 3

    在同路径下,新增全新的 redis.conf 文件,方便自定义

    [root@localhost redis]# ls
    Dockerfile  redis.conf
    
    • 1
    • 2

    通过 Dockerfile 构建 Redis 基础镜像

    [root@localhost redis]# docker build -t myredis .
    Sending build context to Docker daemon  73.22kB
    Step 1/3 : FROM redis
     ---> a55fbf438dfd
    Step 2/3 : COPY redis.conf /usr/local/etc/redis/redis.conf
     ---> a3b1763aeeb2
    Step 3/3 : CMD [ "redis-server", "/usr/local/etc/redis/redis.conf" ]
     ---> Running in 00dd0a1ca908
    Removing intermediate container 00dd0a1ca908
     ---> 86f3dbf1cb71
    Successfully built 86f3dbf1cb71
    Successfully tagged myredis:latest
    [root@localhost redis]# docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    myredis             latest              86f3dbf1cb71        6 seconds ago       95.1MB
    redis               latest              a55fbf438dfd        5 weeks ago         95MB
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    通过 Docker 启动 Redis

    [root@localhost redis]# docker run -d -p 6379:6379 -v /home/docker/redis/redis.conf:/usr/local/etc/redis/redis.conf --name myredis redis redis-server /usr/local/etc/redis/redis.conf
    
    • 1

    通过 telent 192.168.124.15 6379 访问

    访问失败

    我突然想到 redis.conf 默认是只让本机访问的 注释掉了 bind 127.0.0.1

    #bind 127.0.0.1
    
    • 1

    再次调用telent 192.168.124.15 6379 , 报错提醒

    Redis 的报错信息基本 告诉我们如何解决这个问题,再次打开 redis.conf

    # The server only accepts connections from clients connecting from the
    # IPv4 and IPv6 loopback addresses 127.0.0.1 and ::1, and from Unix domain
    # sockets.
    #
    # By default protected mode is enabled. You should disable it only if
    # you are sure you want clients from other hosts to connect to Redis
    # even if no authentication is configured, nor a specific set of interfaces
    # are explicitly listed using the "bind" directive.
    protected-mode no
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    将 protected-mode yes 改为 no 即可 连接成功


    参考: dockerhub-redis

  • 相关阅读:
    综述--知识蒸馏
    如何应对软件可变性?这4种常用的方法肯定要知道
    JVM是什么?Java程序为啥需要运行在JVM中?
    Active Directory 和域名系统(DNS)的相互关系
    mysql 字符串截取
    vue3+vite 中使用百度地图【两种方式】
    AtCoder ABC001C 風力観測题解及翻译(四舍五入)
    React框架核心原理
    优化Java代码效率和算法设计,提升性能
    大数据从入门到精通(超详细版)之Hive的DDL操作
  • 原文地址:https://blog.csdn.net/m0_67401660/article/details/126327262