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: