Docker安装Redis

从docker hub上拉取redis镜像到本地标为3.2

[root@hadoop101 ~]# docker pull redis:3.2
3.2: Pulling from library/redis
f17d81b4b692: Pull complete 
b32474098757: Pull complete 
8980cabe8bc2: Pull complete 
58af19693e78: Pull complete 
a977782cf22d: Pull complete 
9c1e268980b7: Pull complete 
Digest: sha256:7b0a40301bc1567205e6461c5bf94c38e1e1ad0169709e49132cafc47f6b51f3
Status: Downloaded newer image for redis:3.2
docker.io/library/redis:3.2
[root@hadoop101 ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ghjtomcat9          latest              d824ff2c00c6        22 hours ago        732MB
myip_son            latest              bce3f7f4efcd        46 hours ago        277MB
myip_father         latest              eb89c741f944        46 hours ago        276MB
myip2               latest              f9cf5df7c0f5        46 hours ago        276MB
myip                latest              166ac61dcd1b        47 hours ago        276MB
mycentos            1.3                 d9dff72321ec        9 days ago          350MB
ghj/centos          latest              ea55868fb6d4        11 days ago         202MB
atdixin/mytomcat    7.0                 38d1e8f04740        2 weeks ago         508MB
nginx               latest              f949e7d76d63        2 weeks ago         126MB
tomcat              latest              8973f493aa0a        2 weeks ago         508MB
mysql               5.6                 95e0fc47b096        4 weeks ago         257MB
centos              latest              67fa590cfc1c        7 weeks ago         202MB
hello-world         latest              fce289e99eb9        9 months ago        1.84kB
redis               3.2                 87856cc39862        11 months ago       76MB
training/webapp     latest              6fae60ef3446        4 years ago         349MB

使用redis3.2镜像创建容器(也叫运行镜像)
使用镜像

[root@hadoop101 ~]# docker run -p 6379:6379 -v /ghj/myredis/data:/data -v /ghj/myredis/conf/redis.conf:/usr/local/etc/redis/redis.conf -d redis:3.2 redis-server /usr/local/etc/redis/redis.conf --appendonly yes
c9d8645cd8ad821a60e2f37e198b84836cebf0c43c946bf6aceab36fb86e6d2b

在主机/ghj/myredis/conf/redis.conf目录下新建redis.conf文件
vim /ghj/myredis/conf/redis.conf/redis.conf

[root@hadoop101 ~]# vim /ghj/myredis/conf/redis.conf/redis.conf
[root@hadoop101 ~]# cd /ghj/myredis/conf/redis.conf
[root@hadoop101 redis.conf]# ll
总用量 44
-rw-r--r--. 1 root root 41605 10月 10 14:14 redis.conf
[root@hadoop101 redis.conf]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                     NAMES
c9d8645cd8ad        redis:3.2           "docker-entrypoint.s…"   38 minutes ago      Up 38 minutes       0.0.0.0:6379->6379/tcp    elastic_tu
5e67a99464d5        mysql:5.6           "docker-entrypoint.s…"   4 hours ago         Up 4 hours          0.0.0.0:12345->3306/tcp   mysql

测试redis-cli连接上来

[root@hadoop101 redis.conf]# docker exec -it c9d8645cd8ad redis-cli
127.0.0.1:6379> set k1 v1
OK
127.0.0.1:6379> set k2 v2
OK
127.0.0.1:6379> set k3 v3
OK
127.0.0.1:6379> SHUTDOWN

测试持久化文件生成

127.0.0.1:6379> SHUTDOWN
[root@hadoop101 redis.conf]# cd ..
[root@hadoop101 conf]# ll
总用量 0
drwxr-xr-x. 2 root root 24 10月 10 14:14 redis.conf
[root@hadoop101 conf]# cd ..
[root@hadoop101 myredis]# ll
总用量 0
drwxr-xr-x. 3 root              root 24 10月 10 13:40 conf
drwxr-xr-x. 2 systemd-bus-proxy root 28 10月 10 13:40 data
[root@hadoop101 myredis]# cd data/
[root@hadoop101 data]# ll
总用量 4
-rw-r--r--. 1 systemd-bus-proxy input 110 10月 10 14:22 appendonly.aof
[root@hadoop101 data]# vim appendonly.aof
*2
$6
SELECT
$1
0
*3
$3
set
$2
k1
$2
v1
*3
$3
set
$2
k2
$2
v2
*3
$3
set
$2
k3
$2
v3

退出redis容器后回到宿主机的目录下查看。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值