Detailed explanation of installing redis in docker and starting it as a configuration file

Detailed explanation of installing redis in docker and starting it as a configuration file

Update: Recently, it was discovered that the server was hacked by a mining virus, most likely because redis did not set a password!

1. Get the redis image

docker pull redis

Specify the version number:

docker pull redis:4.0.9 

Without adding a version number, the latest version is obtained by default. You can also use docker search redis to view the image source

2. View local image

docker images 

3. Then start the container and do the mapping

①Create a configuration file directory to store redis.conf. Download the file from the official website .

②Create a folder, create a new configuration file, paste the configuration file downloaded from the official website and modify it

mkdir /usr/local/docker
vi /usr/local/docker/redis.conf

③Modify the startup default configuration (from top to bottom):

bind 127.0.0.1 #Comment this part out to limit redis to local access only

protected-mode no #Default is yes, turn on protected mode and limit access to local devices

daemonize no #Default is no. Changing to yes means starting redis as a daemon process. It can run in the background unless the process is killed. Changing to yes will cause the configuration file to start redis to fail.

databases 16 #Number of databases (optional). I changed this just to see if it works. .

dir ./ #Enter the local redis database storage folder (optional)

appendonly yes #redis persistence (optional)

4.docker starts redis command

docker run -p 6379:6379 --name myredis -v /usr/local/docker/redis.conf:/etc/redis/redis.conf -v /usr/local/docker/data:/data -d redis redis-server /etc/redis/redis.conf --appendonly yes

Command explanation:

-p 6379:6379 port mapping: the part before represents the host part, and the part after represents the container part.

--name myredis specifies the container name, which is convenient for viewing and operating .

-v mount directory, the rules are the same as port mapping.

Why do we need to mount the directory: I personally think that Docker is a sandbox isolation-level container. This is its characteristic and security mechanism. It cannot access external (host) resource directories at will, so this mounting directory mechanism is needed.

-d redis means starting redis in the background

redis-server /etc/redis/redis.conf starts redis with the configuration file, loads the conf file in the container, and finally finds the mounted directory /usr/local/docker/redis.conf

--appendonly yes enables redis persistence

5. Check whether the operation is successful

docker ps View running containers

docker logs myredis/27ddba64faa6 (container name/id)

Docker basic commands:

View all docker images

Delete the image (will prompt to stop the container in use first) docker rmi image name/image id

View all containers docker ps -a

View the container running log docker logs container name/container id

Stop the container and run docker stop container name/container id

After terminating the container, run docker start container name/container id

Container restart docker restart container name/container id

Delete container docker rm container name/container id

This is the end of this article about installing redis in docker and starting it with a configuration file. For more information about installing redis in docker and starting it, 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:
  • Docker installs Redis and introduces the visual client for operation
  • How to install redis5.0.3 in docker
  • Docker installs redis 5.0.7 and mounts external configuration and data issues
  • How to deploy redis in linux environment and install it in docker
  • Docker installs the official Redis image and enables password authentication
  • 5 minutes to teach you how to install and start redis in docker (new method)

<<:  The solution to the problem that the web table or div layer is stretched in the web page

>>:  Example of using CSS to achieve semi-transparent background and opaque text

Recommend

CSS Sticky Footer Implementation Code

This article introduces the CSS Sticky Footer imp...

MySQL 8.0.21 free installation version configuration method graphic tutorial

Six steps to install MySQL (only the installation...

How to configure mysql5.6 to support IPV6 connection in Linux environment

Introduction: This article mainly introduces how ...

WeChat applet realizes the effect of shaking the sieve

This article shares the specific code of the WeCh...

Detailed explanation of how to create an updateable view in MySQL

This article uses an example to describe how to c...

MySQL database implements OLTP benchmark test based on sysbench

Sysbench is an excellent benchmark tool that can ...

Linux debugging tools that developers and operators must look at [Recommended]

System performance expert Brendan D. Gregg update...

HTML dl, dt, dd tags to create a table vs. Table creation table

Not only does it reduce the cost of website develo...

What are your principles for designing indexes? How to avoid index failure?

Table of contents Primary key index Create indexe...

Summary of various methods for JS data type detection

Table of contents background What are the methods...

JavaScript flow control (branching)

Table of contents 1. Process Control 2. Sequentia...