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" ]

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

[root@localhost redis]# ls
Dockerfile  redis.conf

通过 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

通过 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

通过 telent 192.168.124.15 6379 访问

访问失败

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

#bind 127.0.0.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

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


参考: dockerhub-redis

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值