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 examples of the difference between methods watch and computed in Vue.js

Table of contents Preface introduce 1. Mechanism ...

Detailed explanation of sshd service and service management commands under Linux

sshd SSH is the abbreviation of Secure Shell, whi...

Bootstrap realizes the effect of carousel

This article shares the specific code of Bootstra...

Using Docker Enterprise Edition to build your own private registry server

Docker is really cool, especially because it'...

How to optimize MySQL deduplication operation to the extreme

Table of contents 1. Clever use of indexes and va...

Graphic tutorial on installing Ubuntu 18.04 on VMware 15 virtual machine

In the past few years, I have been moving back an...

CentOS7.5 installation of MySQL8.0.19 tutorial detailed instructions

1. Introduction This article does not have screen...

Detailed explanation of the solution to font blur when using transform in CSS3

This question is very strange, so I will go strai...

vue+echarts realizes the flow effect of China map (detailed steps)

@vue+echarts realizes the flow effect of China ma...

Mysql anonymous login cannot create a database problem solution

Frequently asked questions Access denied for user...

Docker-compose installation db2 database operation

It is troublesome to install the db2 database dir...

How to import CSS styles into HTML external style sheets

The link-in style is to put all the styles in one...

MySQL uses SQL statements to modify table names

In MySQL, you can use the SQL statement rename ta...

jQuery achieves large-screen scrolling playback effect

This article shares the specific code of jQuery t...