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

Small paging design

Let our users choose whether to move forward or ba...

Vant+postcss-pxtorem implements browser adaptation function

Rem layout adaptation The styles in Vant use px a...

Two ways to enable firewall in Linux service

There are two ways: 1. Service method Check the f...

Installation, activation and configuration of ModSecurity under Apache

ModSecurity is a powerful packet filtering tool t...

Detailed explanation of Linux text editor Vim

Vim is a powerful full-screen text editor and the...

Related commands to completely uninstall nginx under ubuntu16.04

nginx Overview nginx is a free, open source, high...

JavaScript built-in date and time formatting time example code

1. Basic knowledge (methods of date objects) 😜 ge...

Steps for packaging and configuring SVG components in Vue projects

I just joined a new company recently. After getti...

How to use js to determine whether a file is utf-8 encoded

Conventional solution Use FileReader to read the ...

Tutorial on migrating mysql from phpstudy to Linux

Project Purpose Migrate the data in MySQL 5.5.53 ...