Home > Database > Redis > body text

Docker installation Redis instance analysis

WBOY
Release: 2023-05-31 16:52:35
forward
1082 people have browsed it

1. Start docker

systemctl start docker
Copy after login

2. Pull the redis image

docker pull redis:5.0.3
Copy after login

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
Copy after login

4. Create a redis.conf file

touch /root/redis/data /root/redis/conf/redis.conf
Copy after login

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
Copy after login

After modification:

#bind 127.0.0.1
protected-mode no
requirepass yourpassword
Copy after login

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
Copy after login

-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
Copy after login

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
Copy after login

Solution: Restart docker, and then restart the redis container

systemctl restart docker
docker start redis
Copy after login

8. Open firewall port 6379

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

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
Copy after login

Enter the following command after entering redis:

auth "你的密码"
Copy after login

If prompted:

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

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

config set requirepass “你的密码”
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!