docker安装redis7

1.创建目录赋予权限

bash 复制代码
mkdir -p /opt/redis/data
mkdir -p /opt/redis/conf
mkdir -p /opt/redis/log

chmod -R 777 /opt/redis

2.创建挂载的配置文件

bash 复制代码
cat > /opt/redis/conf/redis.conf << 'EOF'
bind 0.0.0.0
port 6379

# 开保护模式(建议开,防止乱连)
protected-mode yes

# 密码(自己改)
requirepass YourRedis!Passw0rd

# 数据目录(对应容器里的 /data 挂载)
dir /data

# RDB 持久化(默认策略)
save 900 1
save 300 10
save 60 10000

# 开启 AOF(更安全,代价是多写一点磁盘)
appendonly yes
appendfsync everysec

# 日志输出到文件(会挂载 /var/log/redis)
logfile "/var/log/redis/redis.log"

# 其他默认就行
EOF

3.启动

bash 复制代码
docker run -d \
  --name redis7 \
  --restart=always \
  -p 6379:6379 \
  -v /opt/redis/data:/data \
  -v /opt/redis/conf/redis.conf:/usr/local/etc/redis/redis.conf \
  -v /opt/redis/log:/var/log/redis \
  redis:7 \
  redis-server /usr/local/etc/redis/redis.conf

4.验证

bash 复制代码
tail -f /opt/redis/log/redis.log

看到输出

复制代码
Ready to accept connections tcp
相关推荐
穷人小水滴14 小时前
用容器编译 VirtualBox 虚拟机软件 (ArchLinux, podman)
linux·容器·virtualbox
EatFans14 小时前
Docker 实战部署:从本地镜像到云服务器,一篇走通 FastAPI + Celery + MySQL + Redis + Nginx
docker·fastapi
judezh14 小时前
api 容器一直 unhealthy?我把一个 Agent 运行时的健康检查逐条拆了,查出四个问题
运维·docker
暗不需求15 小时前
Docker 入门:从「光盘与 DVD」到全栈项目容器化实战
docker·容器·面试
春天花会开13115 小时前
内网 HTTPS 部署实战:私有 CA + Nginx 反向代理全流程复盘
运维·nginx·https
AllFiles15 小时前
K8s Node Exporter 异常 Write 超时排查实录
运维·后端·kubernetes
探索云原生15 小时前
一个 Deployment 就能跑 vLLM,为什么还需要 KServe?
docker·ai·云原生·kubernetes·go
虎头金猫6 天前
4K 视频总卡在公网带宽?用 N1 + OpenList 把网盘播放链路重新理顺
运维·服务器·网络·python·容器·beautifulsoup·pandas
分布式存储与RustFS6 天前
MinIO 官方 Docker 镜像被移除:依赖它的项目该怎么办
docker·云原生·devops·对象存储·minio·分布式存储
AI职业加油站6 天前
AI智能体应用工程师证书:政策红利下的职业新风口
大数据·运维·人工智能·学习·职场发展