1、拉取
docker pull redis:6.0
2、创建配置文件夹及数据文件夹
mkdir -p /dockerStudy/redis/redis1/conf /dockerStudy/redis/redis1/data
3、配置文件
官网:Redis configuration | Redis
寻找自己需要版本配置文件并复制,此次选择redis6,然后在conf下新建redis.conf粘贴进去根据所需更改
bind 127.0.0.1 # 注释掉,解除本地连接限制
protected-mode no # 默认yes,如果设置为yes,则只允许在本机的回环连接,其他机器无法连接。
daemonize no # 默认no 为不守护进程模式,docker部署不需要改为yes,docker run -d本身就是后台启动,不然会冲突
requirepass 123456 # 设置密码
appendonly yes # 持久化
4、run
docker run --name redis1 \
-p 6379:6379 \
-v /dockerStudy/redis/redis1/conf/redis.conf:/etc/redis/redis.conf \
-v /dockerStudy/redis/redis1/data:/data \
-d redis:6.0 redis-server /etc/redis/redis.conf --appendonly yes
5、进入redis容器
docker exec -it redis1 /bin/bash
redis-cli
6、端口暴露
sudo ufw allow 6379
7、外部即可通过连接器连接