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

HTML hyperlink a tag_Powernode Java Academy

Anyone who has studied or used HTML should be fam...

Steps to deploy Spring Boot project using Docker

Table of contents Create a simple springboot proj...

Learning about UDP in Linux

Table of contents 1. Introduction to UDP and Linu...

How to install Linux online software gcc online

Linux online installation related commands: yum i...

Nginx content cache and common parameter configuration details

Use scenarios: The project's pages need to lo...

Detailed tutorial for springcloud alibaba nacos linux configuration

First download the compressed package of nacos fr...

Tic-Tac-toe game implemented in pure CSS3

Operation effect: html <div class="tic-ta...

Thirty HTML coding guidelines for beginners

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

Summary of 28 common JavaScript string methods and usage tips

Table of contents Preface 1. Get the length of a ...

How to query or obtain images in a private registry

Docker queries or obtains images in a private reg...

Implementation of vue-nuxt login authentication

Table of contents introduce Link start Continue t...

Detailed explanation of JavaScript's garbage collection mechanism

Table of contents Why do we need garbage collecti...

How to make full use of multi-core CPU in node.js

Table of contents Overview How to make full use o...

HTML page common style (recommended)

As shown below: XML/HTML CodeCopy content to clip...