The most detailed installation and configuration of redis in docker (with pictures and text)

The most detailed installation and configuration of redis in docker (with pictures and text)

1. Find a suitable version of redis for docker

You can find it in docker hub

https://hub.docker.com/_/redis?tab=tags

insert image description here

2. Install redis using docker

sudo docker pull redis

After installation, docker images即可查看

truedei@truedei:~$ 
truedei@truedei:~$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
redis latest 987b78fc9e38 10 days ago 104MB
httpd latest a8a9cbaadb0c 2 weeks ago 166MB
fjudith/draw.io latest 7b136fc80d31 3 weeks ago 683MB
mysql 5.7.29 f5829c0eee9e 5 weeks ago 455MB
truedei@truedei:~$ 
truedei@truedei:~$ 

3. Prepare the redis configuration file

Because a redis configuration file is needed, it is best to go to the official redis website to download a redis configuration file and use it.

redis Chinese official website: http://www.redis.cn/download.html

insert image description here

After downloading, unzip it:

insert image description here

This redis.conf file is what we need. For safety, copy it and make a backup.

4. Configure the redis.conf configuration file

Modify the redis.conf configuration file:
The main configuration is as follows:

bind 127.0.0.1 #Comment this part to make redis accessible externally
daemonize no #Start as a daemon thread
requirepass 你的密碼#Set a password for redis
appendonly yes #redis persistence defaults to no
tcp-keepalive 300 #Prevents the remote host from forcibly closing an existing connection. The default is 300

5. Create a local directory mapped to docker, that is, the local storage location

Create a local location to store redis;

It can be customized. Because some of my docker configuration files are stored in the /data directory, I still create a redis directory in the /data directory to facilitate later management.

truedei@truedei:redis-5.0.5$ sudo cp -p redis.conf /data/redis/
truedei@truedei:redis-5.0.5$ 

Copy配置文件to the file you just created

Because I am using Linux operating system, I can copy it directly. If you are using Windows, you may need to use FTP to copy it, or directly copy the content and then paste it.

truedei@truedei:redis-5.0.5$ sudo cp -p redis.conf /data/redis/
truedei@truedei:redis-5.0.5$ 

6. Start docker redis

start up:

truedei@truedei:~$ sudo docker run -p 6379:6379 --name redis -v /data/redis/redis.conf:/etc/redis/redis.conf -v /data/redis/data:/data -d redis redis-server /etc/redis/redis.conf --appendonly yes

Parameter explanation:

-p 6379:6379 : Map port 6379 in the container to port 6379 on the host
-v /data/redis/redis.conf:/etc/redis/redis.conf : put the redis.conf configured on the host into this location in the container
-v /data/redis/data:/data : Display the persistent data of redis in the host machine and make data backup
redis-server /etc/redis/redis.conf : This is the key configuration, which allows redis to start according to the configuration of this redis.conf instead of starting without configuration.
–appendonly yes : data persistence after redis starts

7. Check whether the startup is successful

Check whether it is started successfully: sudo docker ps

truedei@truedei:~$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
85cb7d83a2ff redis "docker-entrypoint.s..." 7 minutes ago Up 7 minutes 0.0.0.0:6379->6379/tcp redis
0a122a08125f mysql:5.7.29 "docker-entrypoint.s..." 5 weeks ago Up About an hour 0.0.0.0:3306->3306/tcp, 33060/tcp mysql57
truedei@truedei:~$ 

insert image description here

You can check the logs: sudo docker logs redis

truedei@truedei:~$ sudo docker logs redis
1:C 29 May 2020 01:16:22.107 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:C 29 May 2020 01:16:22.107 # Redis version=6.0.3, bits=64, commit=00000000, modified=0, pid=1, just started
1:C 29 May 2020 01:16:22.107 # Configuration loaded
                _._                                                  
           _.-``__ ''-._                                             
      _.-`` `. `_. ''-._ Redis 6.0.3 (00000000/0) 64 bit
  .-`` .-```. ```\/ _.,_ ''-._                                   
 ( ' , .-` | `, ) Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
 | `-._ `._ / _.-' | PID: 1
  `-._ `-._ `-./ _.-' _.-'                                   
 |`-._`-._ `-.__.-' _.-'_.-'|                                  
 | `-._`-._ _.-'_.-' | http://redis.io        
  `-._ `-._`-.__.-'_.-' _.-'                                   
 |`-._`-._ `-.__.-' _.-'_.-'|                                  
 | `-._`-._ _.-'_.-' |                                  
  `-._ `-._`-.__.-'_.-' _.-'                                   
      `-._ `-.__.-' _.-'                                       
          `-._ _.-'                                           
              `-.__.-'                                               

1:M 29 May 2020 01:16:22.108 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
1:M 29 May 2020 01:16:22.108 # Server initialized
1:M 29 May 2020 01:16:22.108 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
1:M 29 May 2020 01:16:22.108 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
1:M 29 May 2020 01:16:22.108 * Ready to accept connections
truedei@truedei:~$ 

insert image description here

This is the end of this article about the most detailed installation and configuration of redis in docker (with pictures and text). For more relevant content about installing and configuring redis in 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:
  • Detailed explanation of installing redis in docker and starting it as a configuration file
  • Docker installs redis 5.0.7 and mounts external configuration and data issues

<<:  Summary of DTD usage in HTML

>>:  JavaScript to achieve window display effect

Recommend

Vue batch update dom implementation steps

Table of contents Scene Introduction Deep respons...

How to manage users and groups when running Docker

Docker is a management tool that uses processes a...

MySQL tutorial thoroughly understands stored procedures

Table of contents 1. Concepts related to stored p...

Detailed explanation of the use of props in React's three major attributes

Table of contents Class Component Functional Comp...

MySQL database architecture details

Table of contents 1. MySQL Architecture 2. Networ...

Using MySQL database with Python 3.4 under Windows 7

The detailed process of using MySQL database with...

30 Tips for Writing HTML Code

1. Always close HTML tags In the source code of p...

How to solve the timeout during pip operation in Linux

How to solve the timeout problem when pip is used...

MySQL database connection exception summary (worth collecting)

I found a strange problem when deploying the proj...

HTML tag meta summary, HTML5 head meta attribute summary

Preface meta is an auxiliary tag in the head area...

MySQL-8.0.26 Configuration Graphics Tutorial

Preface: Recently, the company project changed th...

Solution to MySQL master-slave delay problem

Today we will look at why master-slave delay occu...

Docker installs and runs the rabbitmq example code

Pull the image: [mall@VM_0_7_centos ~]$ sudo dock...