Install and configure redis in docker

1. Find a suitable redis version of docker

You can go to docker hub to find it.

Docker Hub

2. Use docker to install redis

sudo docker pull redis

3. Prepare the redis configuration file

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

redis Chinese official website: redis 6.0.6 download--Redis China User Group (CRUG)

 After downloading, unzip it:

4. Configure the redis.conf configuration file

Modify redis.confthe configuration file: The main configuration is as follows:

bind 127.0.0.1#Comment out this part so that redis can be accessed externally daemonize no#Start as a daemon thread requirepass 你的密码#Set a password for redis appendonly yes#The default for redis persistence is no tcp-keepalive 300#To prevent the error that the remote host forcibly closes an existing connection, the default is 300

5. Create a directory mapping between local and docker, that is, the location of local storage.

Create a local storage location for redis;

It can be customized because some of my docker redis configuration files are stored in the /usr /datadirectory.

Copy 配置文件it to the file you just created

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

6. Start docker redis

start up:

sudo docker run -p 6379:6379 --name redis -v /usr/data/redis.conf:/etc/redis/redis.conf  -v /usr/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 /usr/data/redis.conf:/etc/redis/redis.conf: Put the redis.conf configured on the host into this location in the container

-v /usr/data:/data: Display the redis persistent data in the host and do data backup redis-server /etc/redis/redis.conf: This is the key configuration, so that redis does not start without configuration, but starts according to the configuration of this redis.conf –appendonly yes: data persistence after redis starts

7. Check whether the startup is successful

Check whether it started successfully:sudo docker ps

Check whether to print 

Guess you like

Origin blog.csdn.net/qq_37544675/article/details/121499462