Home >Operation and Maintenance >Docker >How to solve the problem that docker redis cannot connect

How to solve the problem that docker redis cannot connect

藏色散人
藏色散人Original
2022-01-06 11:44:2915165browse

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

Specify the version number:

docker pull redis:4.0.9

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
After successful startup , enter the redis container


docker exec -it myredis /bin/bash

View the ip assigned by docker to the container

cat /etc/hosts

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!

Statement:
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