Docker battle in the end (X) based on the deployment of Redis service Docker

6413895-aa66875393709148.jpg

First, I wish the older children have a happy holiday, always maintain a childlike innocence.

Benpian practice and recording prequel to deploy MySQL service similar, right when we practice hand familiar with. In my work, our production environment is Ali cloud cloud database Redis version to use, its benefits self-evident. In a development or test environment we can build their own Redis service, then we will be based on Docker to deploy a Redis service.

First, download the image

We use the latest official stable version 5.0.4 of alpine mirror, mirroring provides general if the official version of the alpine, then we are to make use of this type version, compared to other Docker mirror, it takes up less volume.

$ docker pull redis:5.0.4-alpine
6413895-7dd5d628340927d5.png

We downloaded the latest version about the default image to compare the size of the volume

$ docker pull redis

Redis image using the command lists can be seen SIZE comparison, the difference of about 1-fold.

$ docker image ls redis
6413895-53dae41c8033d195.png

Next we delete the latest version

$ docker image rm redis

Then look at the mirror as usual more information

$ docker image inspect redis:5.0.4-alpine

Screenshot section reads as follows

6413895-fb4707ebdb4fca8b.png

Can generally understand the mirrored port and environmental exposure variables and data volume catalog and other information inspect command, usually by the Docker Hub mirror after the official search, you can click the link to Dockerfile corresponds to the version you choose to go, then you can view the more detailed image production details

6413895-817d2edb85ccacc9.png
6413895-0bc4668f86f3a1ab.png

Second, start the service instances Redis

2.1 data persistence directory creation

Redis to persistent data by RDB and AOF in two ways, where we first create a master directory to mount as data persistence directory

$ mkdir -p /docker_volume/redis/data
6413895-539ae628c8bf0654.png

More information can be read official website documents https://redis.io/topics/persistence

2.1 Starting container

Next we start our Redis container by docker command, we simply map 6379 port 30040 port to the host, the / data directory to mount within the container we built above / docker_volume / redis / data directory, then appendonly set to yes

$ docker run -d --restart=unless-stopped -p 30040:6379 \
    -v /docker_volume/redis/data:/data \
    --name redis redis:5.0.4-alpine redis-server --appendonly yes
6413895-b76da1f7d1b5f55a.png

当然,如果你需要使用自定义配置的话,还可以挂载自定义配置文件到容器内的/usr/local/etc/redis/redis.conf,如下

$ docker run -d --restart=unless-stopped -p 30040:6379 \
    -v /docker_volume/redis/data:/data \
    -v /docker_volume/redis/conf/redis.conf:/usr/local/etc/redis/redis.conf \
    --name redis redis:5.0.4-alpine redis-server /usr/local/etc/redis/redis.conf

当然,需要你自己创建 /docker_volume/redis/conf/redis.conf 这么一个配置文件。

2.2 Rancher中部署Redis服务

接下来我们通过Rancher来部署Redis服务,先删除刚才启动的容器

$ docker container stop redis && docker container rm redis
6413895-c8941b19c5537387.png

访问 https://192.168.225.129 进入Rancher的UI中部署工作负载,按照我们前面启动容器执行的命令来映射到UI对应的操作上即可,大致操作如下:

6413895-be6f844071f563e2.png
6413895-d926bc14ab2c0db7.png
6413895-40bafd270c43a713.png

最后点击启动即可,启动成功后会在我们的挂载目录生成一个appendonly.aof文件

6413895-ee626593d25d0804.png

三、客户端连接实例

我们在本地主机通过客户端工具RedisDesktopManager来连接到我们刚才启动的Redis服务实例

6413895-60f6ab2356a11e57.png

接着我们来添加一个KV进行测试,选中db0,鼠标右键点击Add New Key,然后在弹出框输入key与value并保存

6413895-82de4cb127805f7b.png

为了验证数据是否已经持久化,我们查看一下appendonly.aof,执行如下命令

$ cat appendonly.aof
6413895-252d07cb0ccff861.png

四、使用小结

本篇实践记录我们演示了怎么通过容器部署Redis服务以及使用客户端工具连接到Redis服务上,与前一篇部署MySQL服务差不多类似,都是有状态的服务。在生产环境中还是建议采用云数据库的Redis版,或者自建高可用服务。当我们遇到有状态的服务时,对状态的持久化不仅仅只映射一个主机目录这么简单,还要更多的结合实际综合考虑,选择合适的存储方式。当然,在单机环境或只做演示等倒也无伤大雅。如果你有什么疑问或者文中有什么错误的地方,欢迎在留言区留言。

The foregoing navigation
Docker battle in the end (a) the system virtual machine installed ubuntu
Docker battle in the end (b) setting up the environment Docker
Docker battle in the end (c) Rancher2.x installation and use
Docker battle in the end (D) of the installation and use Jenkins
Docker battle in the end (e) make their Jenkins mirror
Docker battle in the end (six) making your own Maven mirror
Docker battle in the end (seven) using multi-stage build Spring Boot application image
Docker battle in the end (eight) yourself build GitLab service
Docker battle in the end (IX) MySQL service deployment

Docker Series battle in the end all for himself wendell_dev original, reproduced please indicate the source.

Reproduced in: https: //www.jianshu.com/p/758c058308da

Guess you like

Origin blog.csdn.net/weixin_34037173/article/details/91074208