systemctl start docker
docker pull redis:5.0.3
Note that if the version number is not specified, pull the latest version
mkdir -p /root/redis/data /root/redis/conf
touch /root/redis/data /root/redis/conf/redis.conf
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 .
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 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
firewall-cmd --zone=public --add-port=6379/tcp --permanent firewall-cmd --reload
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!