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

被折叠的 条评论
为什么被折叠?



