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>