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

Summarize the common application problems of XHTML code

Over a period of time, I found that many people d...

How to implement email alert in zabbix

Implemented according to the online tutorial. zab...

How to install MySQL 5.7.17 and set the encoding to utf8 in Windows

download MySQL official download, select Windows ...

How to solve the problem of automatic package update in Debian system

I don't know when it started, but every time ...

Vue+js realizes video fade-in and fade-out effect

Vue+js realizes the fade in and fade out of the v...

Talking about the practical application of html mailto (email)

As we all know, mailto is a very practical HTML ta...

Steps for Docker to build its own local image repository

1. Environment and preparation 1. Ubuntu 14.04 2....

HTML page native VIDEO tag hides the download button function

When writing a web project, I encountered an intr...

Solution to the long delay of MySQL database master-slave replication

Preface The delay of MySQL master-slave replicati...

You may not know these things about Mysql auto-increment id

Introduction: When using MySQL to create a table,...

Clean XHTML syntax

Writing XHTML demands a clean HTML syntax. Writing...

Detailed tutorial on VMware installation of Linux CentOS 7.7 system

How to install Linux CentOS 7.7 system in Vmware,...