Implementation steps for installing Redis container in Docker

Implementation steps for installing Redis container in Docker

If you want to install software in Docker, you must first download the image from the Docker image repository.

Docker image repository

Install Redis on Docker

1. Find the Redis image

Find the Redis image in the Docker image repository

Redis official website mirror

Docker download Redis image command

Download the Reids image command

2. Download the Redis image

Order describe
docker pull redis Download the latest version of Redis image (in fact, this command is equivalent to: docker pull redis:latest )
docker pull redis:xxx Download the specified version of the Redis image (xxx refers to the specific version number)

Download the specified version of Redis

Check all currently downloaded Docker images

 docker images

3. Create a Redis configuration file

Before starting, you need to create a configuration file for Redis external mounting (/mydata/redis/conf/redis.conf)
The reason why we need to create it first is that the Redis container itself only has the /etc/redis directory, and does not create the redis.conf file. When the redis.conf file does not exist on the server or in the container, Docker will create redis.conf as a directory when executing the startup command, which is not what we want.

## Create directory mkdir -p /mydata/redis/conf
## Create the file touch /mydata/redis/conf/redis.conf

4. Create and start a Redis container

Docker creates Redis container command

docker run \
-d \
--name redis \
-p 6379:6379 \
--restart unless-stopped \
-v /mydata/redis/data:/data \
-v /mydata/redis/conf/redis.conf:/etc/redis/redis.conf \
redis-server /etc/redis/redis.conf \
redis:buster 

Order describe
–name redis The name of the container to start
-d Background operation
-p 6379:6379 Map the container's port 6379 (the latter one) to the host's port 6379 (the former one)
--restart unless-stopped Container restart policy
-v /mydata/redis/data:/data Mount the Redis storage folder on the host
-v /mydata/redis/conf/redis.conf:/etc/redis/redis.conf Mount the configuration folder on the host
-d redis:buster Which version of Redis to start (version of the local image)
redis-server /etc/redis/redis.conf Set redis-server in the Redis container and read /etc/redis/redis.conf every time it starts.
\ Shell command line break

Note: All the commands before the colon are host configurations, and the commands after the colon are mysql container configurations.
--restart unless-stopped : Restart the current container when Docker restarts. However, it does not include containers that were stopped when Docker was restarted.

5. Check whether Redis is running

### View the running Docker container docker ps 
docker ps | grep redis

Check if Redis is running

6. Enter the Redis container

### Enter the Redis container through the Docker command docker exec -it redis /bin/bash
docker exec -it redis bash
### Enter the Redis console redis-cli
### Add a variable with key name and value bella> set name bella
### View the value of the key name> get name


### Or you can directly enter the Redis console through the Docker Redis command (a combination of the above two commands)
docker exec -it redis redis-cli

> Separate commands

Separate commands

> Merge Command

Merge Command

7. Exit the container

exit

8. Modify the Redis configuration file

Modify /mydata/redis/conf/redis.conf

Order Function
appendonly yes Enable Redis persistence (default is no, all information is stored in memory [lost after restart]. Set to yes, it will be stored on the hard disk [still exists after restart])
protected-mode no Disable protected-mode, so that external networks can access it directly (docker seems to be enabled automatically)
bind 0.0.0.0 Set all IP addresses to be accessible (docker seems to be automatically enabled)
requirepass password Set password

9. Enter the Redis console with a password

If you set a password, you need to enter the Redis console using the following command

## Enter the Redis container docker exec -it redis /bin/bash

## Enter the Redis console with the password redis-cli -h 127.0.0.1 -p 6379 -a 123456

Enter the Redis console with a password

This is the end of this article about the implementation steps of installing Redis container with Docker. For more relevant content about installing Redis with Docker, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Introduction to the steps of deploying redis in docker container
  • Docker installation and configuration steps for Redis image
  • Docker builds Redis5.0 and mounts data

<<:  Study on using characters instead of pictures to achieve rounded or sharp corners

>>:  Problems with join queries and subqueries in MySQL

Recommend

How to use Vue's idea to encapsulate a Storage

Table of contents background Function Purpose Ide...

Summary of some problems encountered when integrating echarts with vue.js

Preface I'm currently working on the data ana...

Steps to encapsulate the carousel component in vue3.0

Table of contents 1: Encapsulation idea 2. Packag...

Mysql transaction isolation level principle example analysis

introduction You must have encountered this in an...

Generate OpenSSL certificates in Linux environment

1. Environment: CentOS7, Openssl1.1.1k. 2. Concep...

How to modify the firewall on a Linux server to allow remote access to the port

1. Problem Description For security reasons, the ...

HTML reuse techniques

HTML reuse is a term that is rarely mentioned. Tod...

CSS method of controlling element height from bottom to top and from top to bottom

Let’s start the discussion from a common question...

Special commands in MySql database query

First: Installation of MySQL Download the MySQL s...

Steps for Vue to use Ref to get components across levels

Vue uses Ref to get component instances across le...

Quickly install MySQL5.7 compressed package on Windows

This article shares with you how to install the M...

A collection of possible problems when migrating sqlite3 to mysql

Brief description Suitable for readers: Mobile de...

Detailed explanation of query examples within subqueries in MySql

Where is my hometown when I look northwest? How m...