docker部署redis并挂载数据卷

docker部署redis并挂载数据卷

1、创建目录和配置文件redis.conf

mkdir /docker
mkdir /docker/redis
mkdir /docker/redis/conf
mkdir /docker/redis/data
 
创建redis.conf配置文件
touch /docker/redis/conf/redis.conf
 
redis.conf文件内容自行添加:
切记注释掉:#daemonize yes 否则无法启动容器
重要话说三遍:注释掉#daemonize yes,注释掉#daemonize yes,注释掉#daemonize yes

2、创建启动容器,加载配置文件并持久化数据

docker run -d --privileged=true --restart=always -p 6379:6379 -v /docker/redis/conf/redis.conf:/etc/redis/redis.conf -v /docker/redis/data:/data --name redistest2 redis:4.0 redis-server /etc/redis/redis.conf --appendonly yes

参数说明:

  • –privileged=true:容器内的root拥有真正root权限,否则容器内root只是外部普通用户权限

  • -v /docker/redis/conf/redis.conf:/etc/redis/redis.conf:映射配置文件

  • -v /docker/redis/data:/data:映射数据目录

  • redis-server /etc/redis/redis.conf:指定配置文件启动redis-server进程

  • –appendonly yes:开启数据持久化

redis.conf

# Redis configuration file example.
#
# Note that in order to read the configuration file, Redis must be
# started with the file path as first argument:
# 
# 开始启动时必须如下指定配置文件

# ./redis-server /path/to/redis.conf

# Note on units: when memory size is needed, it is possible to specify
# it in the usual form of 1k 5GB 4M and so forth:
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值