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 redis to applications deployed in docker containers, 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/releasesDownload
the redis release, and select the version that matches the one in the container.
Get redis.conf, comment bind:127.0.0.1
Comment out bind:127.0.0.1
Turn off protected mode
Turn off protected mode
and run with the 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 the startup is successful, enter the redis container

docker exec -it myredis /bin/bash

View the ip assigned to the container by docker

cat /etc/hosts

When other containers connect to redis, change the 127.0.0.1 of the redis connection configuration to the ip just found.

Guess you like

Origin blog.csdn.net/m0_54850604/article/details/123711103