8.2----Docker 部署应用-redis

Redis是一个开源的使用ANSI C语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库,并提供多种语言的API.

安装环境

Linux系统:Ubuntu 16.04
docker版本:18.09.5
redis版本: 5.0

部署思路

  1. OS切换到root用户,并启动docker
$ su root
$ sytemctl start docker
  1. 拉取mysql 8.0 镜像
    访问:https://hub.docker.com 搜索redis 我们可以看到
    image
docker pull redis:5.0
  • 下载完成
root@instance-o70no2nw:~# su root
root@instance-o70no2nw:~# docker pull mysql:8.0.16
latest: Pulling from library/mysql
27833a3ba0a5: Pull complete 
864c283b3c4b: Pull complete 
cea281b2278b: Pull complete 
Digest: sha256:f5f78fe2054b4686da3fddb460eab0b53d04e067c977d6a02fcb5ec25375ed15
Status: Downloaded newer image for mysql:8.0.16
  • 查看镜像
root@instance-o70no2nw:~# docker pull redis:5.0
5.0: Pulling from library/redis
27833a3ba0a5: Already exists 
cde8019a4b43: Pull complete 
97a473b37fb2: Pull complete 
c6fe0dfbb7e3: Pull complete 
39c8f5ba1240: Pull complete 
cfbdd870cf75: Pull complete 
Digest: sha256:000339fb57e0ddf2d48d72f3341e47a8ca3b1beae9bdcb25a96323095b72a79b
Status: Downloaded newer image for redis:5.0
root@instance-o70no2nw:~# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
redis               5.0                 a55fbf438dfd        4 weeks ago         95MB

  1. 启动容器 (重要)

思路:redis可用,需保以下几点:

  1. 端口开放:6379对外开放 -> 需映射端口
  2. 数据持久化:配置文件、存储信息不丢失 -> 需挂载本地卷
  3. 永不停机: restart=always
  4. 守护态运行: -d

基于以上思路, redis:

$ docker run \
--name redis \
--restart=always \
-p 6379:6379 \
-v /usr/local/docker/redis/conf/redis.conf:/usr/local/etc/redis/redis.conf  \
-v /usr/local/docker/redis/redis/data:/data \
-d redis:5.0 /usr/local/etc/redis/redis.conf
  1. 验证
[root@scrt ~]# redis-cli -h 182.61.15.132
182.61.15.139:6379> set users "gaoxuefeng"
OK
182.61.15.139:6379> get users
"gaoxuefeng"
182.61.15.139:6379> 

到此结束

其他资料

Additionally, If you want to use your own redis.conf …

You can create your own Dockerfile that adds a redis.conf from the context into /data/, like so.

FROM redis
COPY redis.conf /usr/local/etc/redis/redis.conf
CMD [ "redis-server", "/usr/local/etc/redis/redis.conf" ]

Alternatively, you can specify something along the same lines with docker run options.

$ docker run -v /myredis/conf/redis.conf:/usr/local/etc/redis/redis.conf --name myredis redis redis-server /usr/local/etc/redis/redis.conf

Where /myredis/conf/ is a local directory containing your redis.conf file. Using this method means that there is no need for you to have a Dockerfile for your redis container.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值