Linux上使用Docker安装Redis

本文介绍了如何在Linux上使用Docker下载Redis镜像,并将Redis容器中的数据挂载到宿主机,以及如何执行连接命令。首先通过`docker pull redis`命令获取Redis镜像,然后在宿主机创建目录并启动容器,使用`-v`参数挂载数据目录和配置文件。最后,通过`docker exec`命令进入Redis容器并使用redis-cli连接Redis服务。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

下载Redis镜像

指令:docker pull redis

[root@localhost conf]# docker pull redis
Using default tag: latest
latest: Pulling from library/redis
7d63c13d9b9b: Pull complete
a2c3b174c5ad: Pull complete
283a10257b0f: Pull complete
7a08c63a873a: Pull complete
0531663a7f55: Pull complete
9bf50efb265c: Pull complete
Digest: sha256:54ee15a0b0d2c661d46b9bfbf55b181f9a4e7ddf8bf693eec5703dac2c0f5546
Status: Downloaded newer image for redis:latest
docker.io/library/redis:latest

将容器中的Redis挂载到宿主机

1.先在Linux宿主机中创建redis的备份文件

[root@localhost conf]# mkdir -p /mydata/redis/conf 
[root@localhost conf]# touch /mydata/redis/conf/redis.conf

2.创建并启动容器,同时挂载文件

[root@localhost conf]# docker run -p 6379:6379 --name redis -v /mydata/redis/data:/data \
 -v /mydata/redis/conf/redis.conf:/etc/redis/redis.conf \
 -d redis redis-server /etc/redis/redis.conf
758c0211e97a90f885fca9cc19627df146863c072b901c6f79224ced813ffc1a

使用Redis镜像执行连接命令

[root@localhost conf]# docker exec -it redis redis-cli
127.0.0.1:6379>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值