- A+
- https://www.studenty.cn/?p=1111
安装 Redis
- [root@centos7 /]# docker pull redis
因为 redis 默认配置你会发现只能够本地连接,不能进行远程访问,使用 Redis Desktop Manager连接都会报错,因此需要手动挂载 redis 配置文件
- //数据存放目录
- [root@centos7 /]# mkdir -p /docker/redis/data
- //配置文件存放目录
- [root@centos7 /]# mkdir -p /docker/redis/conf
- #bind 127.0.0.1 //允许远程连接
- protected-mode no
- appendonly yes //持久化
- requirepass password //密码
- [root@centos7 /]# docker run --name myredis -p 6379:6379 -v /docker/redis/data:/data -v /docker/redis/conf/redis.conf:/etc/redis/redis.conf -d redis redis-server /etc/redis/redis.conf
- --name 给容器起一个名
- -p 端口映射 宿主机:容器
- -v 挂载自定义配置 自定义配置:容器内部配置
- -d 后台运行
- redis-server 使用指定的配置文件启动
- [root@centos7 /]# docker ps
- [root@centos7 /]# docker exec -it myredis redis-cli
- 127.0.0.1:6379> auth password
- OK
- 127.0.0.1:6379> set name yuxi
- OK
- 127.0.0.1:6379> get name
- yuxi
- 注意如果出现该错误: (error) NOAUTH Authentication required.
- 说明没有输入密码进行验证,请输入:auth 你的密码