Docker 安装Redis 以配置文件启动redis

一、拉取镜像

//拉取redis镜像
docker pull redis 
//查看所有镜像
docker images  

二. redis配置文件修改(重要)

  /root/redis/redis01/conf/redis.conf 中daemonize=NO。非后台模式,如果为YES 会的导致 redis 无法启动,因为后台会导致docker无任务可做而退出

三、启动redis

docker run -p 6379:6379 --name myredis-6379 --privileged=true -v /root/redis/redis01/conf/redis.conf:/etc/redis/redis.conf -v /root/redis
/redis01/data:/data -d redis:5.0.7 redis-server /etc/redis/redis.conf --appendonly yes

1. -p 6378:6379  容器redis 端口6379 映射 宿主机未6378

2. --name myredis-6379 容器 名字 为 myredis-6379

3. --privileged=true 给容器加上特定的权限

4. -v /root/redis/redis01/conf/redis.conf:/etc/redis/redis.conf   容器 /etc/redis/redis.conf 配置文件 映射宿主机 /root/redis/redis01/conf/redis.conf。  会将宿主机的配置文件复制到docker中。

 重要: 配置文件映射,docker镜像redis 默认无配置文件。

5 -v /root/redis/redis01/data:/data  容器 /data 映射到宿主机 /root/redis/redis01/data

6.-d redis  后台模式启动 redis 

7. redis-server /etc/redis/redis.conf    redis 将以 /etc/redis/redis.conf 为配置文件启动
8. --appendonly yes  开启redis 持久化

重要:  docker 镜像reids 默认 无配置文件启动

ps:如果启动失败通过:docker logs -f -t --tail 10 myredis-6379查看启动日志

猜你喜欢

转载自www.cnblogs.com/mengY/p/12658996.html
今日推荐