docker安装redis案例

第一步:

docker pull redis # 拉取镜像
mkdir /shw/redis/conf #创建配置文件目录

第二步:

从官网获取 redis.conf 配置文件。
修改默认配置文件:

bind 127.0.0.1 #注释掉这部分,这是限制redis只能本地访问
protected-mode no #默认yes,开启保护模式,限制为本地访问
daemonize no#默认no,改为yes会使配置文件方式启动redis失败
dir ./ #输入本地redis数据库存放文件夹(可选)
appendonly yes #redis持久化(可选)

 修改好配置文件之后,在/shw/redis/conf目录下添加redis.conf文件。

第三步:

docker run -p 6379:6379 --name redis -v /shw/redis/conf:/etc/redis/redis.conf -v /shw/redis/data:/data -d redis redis-server /etc/redis/redis.conf/redis.conf --appendonly yes

参数说明:
docker run -p 6379:6379 --name redis  # 映射端口,起名字
-v /shw/redis/conf:/etc/redis/redis.conf # 挂载配置文件,注意/etc/redis/redis.conf中redis.conf是一个目录
-v /shw/redis/data:/data # 挂载数据文件
-d redis redis-server /etc/redis/redis.conf/redis.conf # 以配置文件的方式启动,在上面已经挂载/shw/redis/conf/redis.conf
--appendonly yes # 持久化

docker exec -it [容器ID] /bin/bash
redis-cli

想看镜像的内部目录结构,就得先把镜像运行起来,进入容器中,使用ls或者ls -l查看,ll不行。

docker exec -it [容器id] /bin/bash #进入容器
docker inspect [容器id] # 查看容器挂载情况,在Mounts后面
原文地址:https://www.cnblogs.com/sun2020/p/13138278.html