1、方案一:

        直接在docker-compose.yml文件中添加command命令。

version: "3.8"

networks:

flask_li:

services:

redis:

image: redis:7.0.11

container_name: my_redis

restart: always

ports:

- "6379:6379"

command: redis-server --requirepass yourpassword

volumes:

- ./data/redis/data:/data

        然后直接在其所在目录下执行 docker-compose up -d,即可在 Docker 中生成一个带密码的 Redis 容器。

2、方案二

version: "3.8"

networks:

flask_li:

services:

redis:

image: redis:7.0.11

container_name: my_redis

restart: always

ports:

- "6379:6379"

command: redis-server /usr/local/etc/redis/redis.conf

volumes:

- ./data/redis/data:/data

- ./data/redis/config/redis.conf:/usr/local/etc/redis/redis.conf

其中:command 代表生成容器后要执行的命令。

在redis.conf中设置密码:

3、总结

        方案二的好处是可以更多的定制 Redis 的配置,方案一的好处是可以快速启动一个带免密的 Docker Redis 实例而不需要依赖外部的 redis.conf。

文章链接

评论可见,请评论后查看内容,谢谢!!!评论后请刷新页面。