Home  >  Article  >  Database  >  Docker installation Redis instance analysis

Docker installation Redis instance analysis

WBOY
WBOYforward
2023-05-31 16:52:351087browse

1. Start docker

systemctl start docker

2. Pull the redis image

docker pull redis:5.0.3

Note that if the version number is not specified, pull the latest version

3. Create a local redis mounting directory

mkdir -p /root/redis/data /root/redis/conf

4. Create a redis.conf file

touch /root/redis/data /root/redis/conf/redis.conf

5. Modify the redis.conf file

Download link: https: //www.lanzous.com/i68hlah

This configuration file can be downloaded online at http://download.redis.io/releases/, and the following configurations are mainly modified.

Before modification:

bind 127.0.0.1
protected-mode yes
#requirepass yourpassword

After modification:

#bind 127.0.0.1
protected-mode no
requirepass yourpassword

where yourpassword is your password .

6. Create a redis container

docker run -d --name redis -p 6379:6379 -v /root/redis/conf/redis.conf:/redis.conf -v /root/redis/data:/data redis:5.0.3 redis-server --appendonly yes

-d Run in the background
-p Map the port to the host's port
-v Mount the host directory to the container's directory
redis-server --appendonly yes: Execute the redis-server startup command in the container and open the redis persistence configuration

Docker installation Redis instance analysis

7. Start the created redis container

docker start redis

If you execute the above command and the following error is reported:

Error response from daemon: driver failed programming external connectivity on endpoint redis (086c7fdf5eb7a696753d7414e93202eefd474370658e8c090bca5608c6e29a11):  (iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 6379 -j DNAT --to-destination 172.17.0.2:6379 ! -i docker0: iptables: No chain/target/match by that name.
 (exit status 1))
Error: failed to start containers: redis

Solution: Restart docker, and then restart the redis container

systemctl restart docker
docker start redis

8. Open firewall port 6379

firewall-cmd --zone=public --add-port=6379/tcp --permanent
firewall-cmd --reload

9. Local connection test

Docker installation Redis instance analysis

10. Connection error

Docker installation Redis instance analysis

If the connection fails, first check whether you can log in to redis on the server

docker exec -it redis redis-cli

Enter the following command after entering redis:

auth "你的密码"

If prompted:

(error) ERR Client sent AUTH, but no password is set

Indicates our settings The password does not take effect, then you need to execute the following command again:

config set requirepass “你的密码”

The above is the detailed content of Docker installation Redis instance analysis. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete