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

A brief discussion on the magic of parseInt() in JavaScript

cause The reason for writing this blog is that I ...

Implementation code for operating mysql database in golang

Preface Golang provides the database/sql package ...

Example of building a Jenkins service with Docker

Pull the image root@EricZhou-MateBookProX: docker...

Deployment and Chinese translation of the docker visualization tool Portainer

#docker search #docker pull portainer 1. Download...

Detailed explanation of the loop form item example in Vue

Sometimes we may encounter such a requirement, th...

jQuery plugin to achieve image comparison

This article example shares the specific code of ...

Summary of DTD usage in HTML

DTD is a set of grammatical rules for markup. It i...

Implementation of postcss-pxtorem mobile adaptation

Execute the command to install the plugin postcss...

Vue sample code for implementing two-column horizontal timeline

Table of contents 1. Implement the component time...

Web Design Help: Web Font Size Data Reference

<br />The content is reproduced from the Int...

Teach you how to get the pointer position in javascript

The method of obtaining the position of the point...

CSS World--Code Practice: Image Alt Information Presentation

Using the <img> element with the default sr...

How to execute Linux shell commands in Docker

To execute a shell command in Docker, you need to...