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 implement page jump in Vue project

Table of contents 1. Create a vue-cli default pro...

Vue sample code for easily implementing virtual scrolling

Table of contents Preface Rolling principle accom...

MySQL 8.0.13 installation and configuration method graphic tutorial under win10

I would like to share the installation and config...

Introducing the code checking tool stylelint to share practical experience

Table of contents Preface text 1. Install styleli...

How to configure Linux CentOS to run scripts regularly

Many times we want the server to run a script reg...

How to connect to a remote docker server with a certificate

Table of contents 1. Use scripts to encrypt TLS f...

How to use vue3+TypeScript+vue-router

Table of contents Easy to use Create a project vu...

How to monitor Linux server status

We deal with Linux servers every day, especially ...

Complete steps to set up automatic updates in CentOS 8

The best thing you can do for your data and compu...

Code for implementing simple arrow icon using div+CSS in HTML

In web design, we often use arrows as decoration ...

The perfect solution for MySql version problem sql_mode=only_full_group_by

1. Check sql_mode select @@sql_mode The queried v...

Complete step record of Vue encapsulation of general table components

Table of contents Preface Why do we need to encap...

Implementation of running SQL Server using Docker

Now .net core is cross-platform, and everyone is ...

HTML optimization techniques you must know

To improve the performance of web pages, many dev...

How to quickly copy large files under Linux

Copy data When copying data remotely, we usually ...