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

发布了83 篇原创文章 · 获赞 58 · 访问量 17万+

猜你喜欢

转载自blog.csdn.net/qq_38423105/article/details/89785312
今日推荐