Docker case analysis: Building a Redis service

Docker case analysis: Building a Redis service

Use the official redis image to build the database service. The current latest version corresponds to version 5.0.8. Mount local data directories, configuration directories, and log directories to facilitate data backup and migration.

1 Create mount directories and files

Create a configuration directory ~/docker/redis/conf, a data directory ~/docker/redis/data, and a log directory ~/docker/redis/log on the host, and create a file ~/docker/redis/conf/redis.conf in the configuration directory. The contents of the configuration file are as follows.

logfile /log/redis.log

The final directory structure is as follows:

insert image description here

insert image description here

2 Pull the redis image

Use the latest official version of redis image, currently version 5.0.8.

docker pull redis

3 Create a container and start it

Mount local configuration, data, and log directories into the container.

# --name redis The container name is redis
# -p 6379:6379 binds local port 6379 to container port 6379 (redis service port)
conf:/usr/local/etc/redis/redis.conf -v ~/docker/redis/log/:/log/ -v ~/docker/redis/data:/data -d redis redis-server /usr/local/etc/redis/redis.conf --appendonly yes

After the container is started, you can view the redis operation status through the local ~/docker/redis/log/redis.log.

insert image description here

4 Redis usage

Use the local redis-cli client to connect to redis and add the key value v=1. After performing several operations, the appendonly.aof file in the ~/docker/redis/data directory already has relevant data content.

insert image description here

insert image description here

5 Simulating the effect of data migration

If you stop the redis container at this time and start a new redis container to mount the same directory, the redis in the new container will already contain the data in the previous container.

docker run --name redis1 -p 6379:6379 -v ~/docker/redis/conf/redis.conf:/usr/local/etc/redis/redis.conf -v ~/docker/redis/log/:/log/ -v ~/docker/redis/data:/data -d redis redis-server /usr/local/etc/redis/redis.conf --appendonly yes

insert image description here

If you need more customized configuration, you can add it in the local ~/docker/redis/conf/redis.conf file

Refer to the official redis image

The above is my personal experience. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

You may also be interested in:
  • Example of how to quickly build a Redis cluster with Docker
  • How to build a redis cluster using docker
  • How to deploy MySQL and Redis services using Docker
  • How to deploy and start redis in docker

<<:  Solution to the img tag problem below IE10

>>:  How to position the header at the top using CSS sticky layout

Recommend

Detailed explanation of MySQL's MERGE storage engine

The MERGE storage engine treats a group of MyISAM...

The use and methods of async and await in JavaScript

async function and await keyword in JS function h...

MySQL paging query optimization techniques

In applications with paging queries, queries that...

Detailed example of creating and deleting tables in MySQL

The table creation command requires: The name of...

Detailed explanation of MySQL alter ignore syntax

When I was at work today, the business side asked...

VUE implements timeline playback component

This article example shares the specific code of ...

js memory leak scenarios, how to monitor and analyze them in detail

Table of contents Preface What situations can cau...

MySQL paging performance exploration

Several common paging methods: 1. Escalator metho...

Keepalived+Nginx+Tomcat sample code to implement high-availability Web cluster

Keepalived+Nginx+Tomcat to achieve high availabil...

Summary of using the exclamation mark command (!) in Linux

Preface Recently, our company has configured mbp,...

Beginners learn some HTML tags (1)

Beginners can learn HTML by understanding some HT...

Introduction to ApplicationHost.config (IIS storage configuration area file)

For a newly created website, take ASP.NET MVC5 as...

How to quickly build a LAMP environment on CentOS platform

This article uses an example to describe how to q...

Detailed explanation of MySQL transactions and MySQL logs

Transactional Characteristics 1. Atomicity: After...