Docker installation and configuration steps for Redis image

Docker installation and configuration steps for Redis image

Preface

This tutorial demonstrates how to install the Redis image, create a Redis container, and map ports to mount data volumes and configuration data.

insert image description here

environment

  • CentOS 7
  • Docker 20.10.10

Install

Pull the image

docker pull redis

insert image description here

View Mirror

docker images

insert image description here

Create and start the MySQL container

Create data directories and configuration files

Create a configuration folder

mkdir -p /mydata/redis/conf

Create a configuration file

touch /mydata/redis/conf/redis.conf

Reminder to avoid pitfalls

Create the redis.conf configuration file in advance. Because when the local /mydata/redis/conf/redis.conf is mounted to /etc/redis/redis.conf , the last redis.conf in the path is not regarded as a file, but as a directory. Therefore, if we want to mount the configuration file redis.conf on the local machine into the Docker container, we need to create the configuration file in advance.
#######################################
Complete the above steps to create data directories and configuration files~
#######################################

Create and start the MySQL container command

sudo 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

Parameter Description

  • -p 3306:3306 : Map the container's port 6379 to the host's port 6379
  • --name redis : Define the container name as redis
  • -v /mydata/redis/data:/data : Mount the Redis data folder to the host
  • -v /mydata/redis/conf/redis.conf:/etc/redis/redis.conf : Mount the Redis configuration folder to the host
  • -d redis redis-server /etc/redis/redis.conf : Run in the background and start with the redis image according to the following configuration file /etc/redis/redis.conf

insert image description here

View running containers

docker ps

insert image description here

Connecting to Redis in Docker

docker exec -it redis redis-cli

insert image description here

Store Value

set name zhangsan

insert image description here


Value

get name

insert image description here

Setting up Redis persistent storage

By default, redis data is stored in memory. After restart, the data is lost. After setting persistent storage, the data will still be in memory after restart.

echo "appendonly yes" >> /mydata/redis/conf/redis.conf

This is the end of this article about the implementation steps of Docker installation and configuration of Redis image. For more relevant content about Docker installation of Redis image, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Redis installation and configuration process in Windows and remote access function
  • Redis installation configuration and common commands
  • Redis basic knowledge, installation, deployment, and configuration notes
  • Installation and configuration method of Redis database
  • Detailed installation and configuration tutorial of Redis database

<<:  Summary of HTML horizontal and vertical centering issues

>>:  Introduction to JavaScript array deduplication and flattening functions

Recommend

How to modify the "Browse" button of the html form to upload files

Copy code The code is as follows: <!DOCTYPE HT...

Mobile front-end adaptation solution (summary)

I searched online and found that many interviews ...

Automatically load kernel module overlayfs operation at CentOS startup

To automatically load kernel modules in CentOS, y...

Script to quickly list all host names (computer names) in the LAN under Linux

Recently, I have a need to list all host names in...

Set the input to read-only via disabled and readonly

There are two ways to achieve read-only input: dis...

Use Element+vue to implement start and end time limits

This article example shares the specific code for...

A brief discussion on which fields in Mysql are suitable for indexing

Table of contents 1 The common rules for creating...

javascript:void(0) meaning and usage examples

Introduction to void keyword First of all, the vo...

Win10 uses Tsinghua source to quickly install pytorch-GPU version (recommended)

Check whether your cuda is installed Type in the ...

HTML implements read-only text box and cannot modify the content

Without further ado, I will post the code for you...

VMware virtual machine three connection methods example analysis

NAT In this way, the virtual machine's networ...

MySQL high availability solution MMM (MySQL multi-master replication manager)

1. Introduction to MMM: MMM stands for Multi-Mast...