Home > Article > Operation and Maintenance > How to solve the problem that docker redis cannot connect
Solution to the problem that docker redis cannot connect: 1. Pull the redis container; 2. Download and obtain the configuration file redis.conf from github; 3. Check the IP assigned by docker to the container; 4. Use the configuration file Just run redis.
The operating environment of this article: Windows 7 system, redis version 4.0.9, Dell G3 computer.
How to solve the problem that docker redis cannot connect?
The application deployed to the docker container cannot connect to the redis container
##Each container run by docker is isolated. Redis does not allow external connections by default. Therefore, if you want to connect the application deployed in the docker container to redis, you need to modify the default configuration of redis. Here we can run redis with the configuration file. Pull the redis containerdocker pull redis
docker pull redis:4.0.9Download and get the configuration file redis.conf from githubhttps://github. com/antirez/redis/releases
Download the redis release version, and select the version that matches the one in the container.
Get redis.conf, comment bind:127.0.0.1
Turn off protected mode
Run with configuration file
docker run -p 6379:6379 --name myredis -v /usr/local/docker/redis.conf:/etc/redis/redis.conf -d redis redis-server /etc/redis/redis.conf --appendonly yesAfter successful startup , enter the redis container
docker exec -it myredis /bin/bashView the ip assigned by docker to the container
cat /etc/hostsWhen other containers connect to redis, you must change the 127.0.0.1 in the redis connection configuration to the ip you just found. Every container run by docker is isolated. Redis does not allow external connections by default, so you want to deploy it inside a docker container. To connect an application to redis, you need to modify the default configuration of redis. Here we can run redis with the configuration file. Recommended study: "
docker usage tutorial"
The above is the detailed content of How to solve the problem that docker redis cannot connect. For more information, please follow other related articles on the PHP Chinese website!