如何使用不同的配置文件在docker上运行Redis?

前端之家收集整理的这篇文章主要介绍了如何使用不同的配置文件在docker上运行Redis?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我想在docker上运行的Redis服务器上设置密码.我跟随了https://registry.hub.docker.com/_/redis/的instcruction:

1.我创建了一个包含Dockerfile的文件夹,其中包含:

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

2.我添加了一个redis.conf文件

  1. requirepass thepassword

我使用以下方法构建了图像:

  1. docker build -t ouruser/redis .

我开始了容器:

  1. docker run --name my-redis -p 0.0.0.0:6379:6379 -d ouruser/redis redis-server --appendonly yes

redis服务器没有任何密码!我不懂为什么.

最佳答案
运行命令:

  1. docker run --name my-redis -p 0.0.0.0:6379:6379 -d ouruser/redis redis-server --appendonly yes

使用redis-server覆盖Dockerfile中定义的CMD – 依赖是,因此您的conf文件将被忽略.只需将conf文件的路径添加到run命令中:

  1. docker run --name my-redis -p 0.0.0.0:6379:6379 -d ouruser/redis redis-server /usr/local/etc/redis/redis.conf --appendonly yes

或者,设置入口点脚本或向CMD指令添加–appendonly yes.

猜你在找的Docker相关文章