使用 Docker 安装 Redis 6.2.14。
拉取 Redis 镜像
1
| docker pull redis:6.2.14
|
创建挂载目录
1
| sudo mkdir /docker-data/redis
|
下载 redis.conf
1 2
| cd /docker-data/redis sudo wget https://raw.githubusercontent.com/redis/redis/6.2.14/redis.conf
|
设置权限
修改默认配置
编辑配置文件:
1
| sudo vi /docker-data/redis/redis.conf
|
修改以下配置:
1 2 3 4 5
| protected-mode no daemonize no requirepass 123456 appendonly yes
|
启动 Redis
1 2 3 4 5
| docker run --name redis \ -p 6379:6379 \ -v /docker-data/redis/redis.conf:/etc/redis/redis.conf \ -v /docker-data/redis:/data \ -d redis:6.2.14 redis-server /etc/redis/redis.conf --appendonly yes
|
参数说明
-p 6379:6379:端口映射,前面是宿主机端口,后面是容器端口。
--name redis:指定容器名称。
-v:挂载文件或目录,前面是宿主机路径,后面是容器路径。
-d redis:6.2.14 redis-server /etc/redis/redis.conf:在后台启动 Redis,并加载容器内的配置文件。
--appendonly yes:开启 Redis 持久化。
查看运行状态