docker 安裝Redis

下载镜像

[vagrant@localhost ~]$ sudo docker pull redis
Using default tag: latest
latest: Pulling from library/redis
69692152171a: Already exists
a4a46f2fd7e0: Pull complete
bcdf6fddc3bd: Pull complete
2902e41faefa: Pull complete
df3e1d63cdb1: Pull complete
fa57f005a60d: Pull complete
Digest: sha256:7e2c6181ad5c425443b56c7c73a9cd6df24a122345847d1ea9bb86a5afc76325
Status: Downloaded newer image for redis:latest
docker.io/library/redis:latest
[vagrant@localhost ~]$ sudo docker images
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
redis        latest    fad0ee7e917a   2 weeks ago   105MB
mysql        5.7       2c9028880e58   5 weeks ago   447MB

配置redis

  • 创建redis配置文件
[vagrant@localhost ~]$ sudo mkdir -p /mydata/redis/conf
[vagrant@localhost ~]$ sudo touch /mydata/redis/conf/redis.conf
  • redis.conf 中配置redis 数据持久化
[root@localhost vagrant]# echo "appendonly yes"  >> /mydata/redis/conf/redis.conf
[root@localhost vagrant]# cd /mydata/redis/
[root@localhost redis]# ls
conf  data
[root@localhost redis]# cd conf/
[root@localhost conf]# ls
redis.conf
[root@localhost conf]# pwd
/mydata/redis/conf
[root@localhost conf]# cat redis.conf
appendonly yes

启动redis

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
[root@localhost vagrant]# 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
833240adde967afc6b2e924e4d46eadf9fcdb3fb912b4161fd0f6c3dae5637ac

连接测试

[root@localhost vagrant]# docker exec -it redis redis-cli
127.0.0.1:6379> set name herion
OK
127.0.0.1:6379> get name
"herion"
127.0.0.1:6379>

设置redis容器在docker启动的时候自动启动

[root@localhost conf]# docker update redis --restart=always
redis
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值