Docker container specifies the mapped port to start redis

After the server docker container starts redis, it is found that the external cannot access redis at all

After starting redis, docker cannot access externally and refuses to connect

insert image description here

There may be a problem because the redis configuration file is not specified to start

But before starting the mirror, we need to go to the official website to download the redis configuration file redis.conf file. Note that different versions of the redis configuration file have different content. To download the corresponding version of the redis configuration file
redis.conf file address: https://redis.io/docs/manual/config/

Create a redis.conf file by yourself, copy the content of redis.conf from the official website, and then modify the content of the configuration file
1. If you want external access, first comment
1. If the prime minister accesses externally, the bing comment will be
2 in the "bind" line, and set the appendonly persistence to yes
insert image description here
3. If you want to set the requirepass password
insert image description here
and finally run to create and start the redis container

docker run \
-p 6379:6379 \  docker与宿主机的端口映射
--name redis \  启动命名redis容器的名字
-v /docker/redis/redis.conf:/etc/redis/redis.conf \  挂载redis.conf文件
-v /docker/redis/data:/data \  挂在redis的持久化数据
--restart=always \  设置redis容器随docker启动而自启动
-d redis:7.0.4 redis-server /etc/redis/redis.conf \  指定redis在docker中的配置文件路径,-d后台启动redis

Guess you like

Origin blog.csdn.net/m0_49412847/article/details/126241240