How to solve the problem that docker redis cannot connect

藏色散人
Release: 2022-01-14 17:51:53
Original
14917 people have browsed it

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.

How to solve the problem that docker redis cannot connect

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 container

docker pull redis
Copy after login

Specify the version number:

docker pull redis:4.0.9
Copy after login

Download and get the configuration file redis.conf from github

https://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

How to solve the problem that docker redis cannot connect Turn off protected mode

How to solve the problem that docker redis cannot connect 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 yes
Copy after login

After successful startup , enter the redis container


docker exec -it myredis /bin/bash
Copy after login

View the ip assigned by docker to the container

cat /etc/hosts
Copy after login
When 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!

Related labels:
source:php.cn
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!