使用 docker 创建 Redis 服务 使用docker创建Redis服务 配置docker镜像源 123456"registry-mirrors": [ "https://4346hkfk.mirror.aliyuncs.com", "https://docker.mirrors.ustc.edu.cn", "https://hub-mirror.c.163.com", "https://reg-mirror.qiniu.com"] 拉取镜像 1docker pull redis 创建配置文件 redis并不会创建redis.conf配置文件,而在启动容器时,如果宿主机以及容器内都没有配置文件,docker会自动创建,但是docker创建的redis.conf是目录,并不是文件,因此我们需要提前创建这个文件。 123mkdir -p ~/redis/conftouch ~/redis/conf/redis.conf 配置Redis 编辑redis.conf 1vim ~/redis/conf/redis.conf 设置以下配置: 1234appendonly yes # 数据持久化protected-mode no # 外部网络访问bind 0.0.0.0 # 所有ip都可以访问requirepass 123456 # 设置访问密码 启动容器 1docker run --name redis -p 6379:6379 -v ~/redis/data:/data -v ~/redis/conf/redis.conf:/etc/redis/redis.conf -d redis:latest redis-server /etc/redis/redis.conf 进入容器 1234567docker exec -it redis bash--------------------------root@0d0142d45f55:/data# redis-cli -a 123456Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.127.0.0.1:6379> set ping pongOK127.0.0.1:6379> 通过redis桌面管理工具查看是否生效: 说明redis运行成功! docker #docker 使用 docker 创建 Redis 服务 https://bald3r.wang/2023/07/27/使用-docker-创建-Redis-服务/ 作者 Allen 发布于 2023年7月27日 许可协议 NestJS 入门(四)Redis 和注销 上一篇 ES6 Iterator遍历器 下一篇