1、准备工作
bash
docker pull redis:6.2.6
Pwd="/data/software/redis"
mkdir ${Pwd}/{data,logs} -p
chmod 777 ${Pwd}/logs
2、添加配置文件
bash
cat > ${Pwd}/data/redis.conf << EOF
bind 0.0.0.0
port 6379
requirepass 123456
logfile /tmp/redis.log
save 60 1
EOF
3、运行容器
bash
docker run -itd --name redis \
-v ${Pwd}/data:/data \
-v ${Pwd}/logs:/tmp \
-v /etc/localtime:/etc/localtime \
-p 6379:6379 \
--restart=always \
redis:6.2.6 redis.conf
4、连接Redis数据库,测试服务是否正常
bash
docker exec -it redis redis-cli
127.0.0.1:6379> AUTH 123456 # 输入密码
OK