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

11
我希望您在运行在Docker上的Redis服务器上设置密码。我已经按照https://registry.hub.docker.com/_/redis/上的说明进行了操作:
1. 我已经创建了一个包含Dockerfile的文件夹,其中包含以下内容:
FROM redis  
COPY redis.conf /usr/local/etc/redis/redis.conf  
CMD [ "redis-server", "/usr/local/etc/redis/redis.conf" ] 

2.我添加了一个redis.conf文件,其中包含:

requirepass thepassword

3.我使用以下命令构建了镜像:

docker build -t ouruser/redis .

4.我启动了容器:

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

Redis服务器没有设置密码!我不明白为什么。

1个回答

18

运行命令:

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

使用redis-server --appendonly yes覆盖Dockerfile中定义的CMD,这样你的conf文件将被忽略。只需将conf文件路径添加到运行命令中:

使用redis-server --appendonly yes覆盖Dockerfile中定义的CMD,这样你的conf文件将被忽略。只需将conf文件路径添加到运行命令中:

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接