问题描述
我有一个Docker Compose文件,该文件启动两项服务:Redis和Redis Commander.使用默认的Redis端口6379可以正常工作.将Redis端口更改为 6380
后,Redis Commander无法再连接到Redis.
I have a Docker Compose file that starts two services: Redis and Redis Commander. Using the default Redis port 6379 works fine. After changing the Redis port to 6380
Redis Commander cannot connect to Redis anymore.
错误:
setUpConnection Redis error Error: connect ECONNREFUSED 172.19.0.2:6380
这是 docker-compose.yml
文件:
version: '3.7'
services:
redis:
container_name: redis
hostname: redis
image: sameersbn/redis:4.0.9-2
ports:
- "6380:6379"
expose:
- "6380"
volumes:
- type: volume
source: redis-data
target: /data
restart: always
redis-commander:
container_name: redis-commander
hostname: redis-commander
image: rediscommander/redis-commander:latest
restart: always
environment:
- REDIS_HOSTS=local:redis:6380
ports:
- "8082:8081"
volumes:
redis-data: {}
我可以使用以下节点代码在端口 6380
上连接到Redis:
I can connect to Redis on port 6380
using the following Node code:
import redis from 'redis'
const config = {
host: '127.0.0.1',
port: 6380,
no_ready_check: true
}
const client = redis.createClient(config.port, config.host)
client.set('expireName', 'nidkil', (err, reply) => {
if (err) {
console.error('Error occurred:', err)
} else {
console.log('Response:', reply)
}
})
如果在 docker-compose.yml
中将端口改回 6379
,则Redis Commander可以连接.
If I change the port back to 6379
in the docker-compose.yml
then Redis Commander can connect.
关于如何使Redis Commander在端口 6380
上连接到Redis的任何建议?
Any suggestions how I can make Redis Commander connect to Redis on port 6380
?
推荐答案
@Mihai的回答帮助我找出了解决方案.我需要更改Redis正在运行的端口以及裸露的端口.这是工作中的Docker撰写文件.
The answer of @Mihai helpt me figure out the solution. I needed to change the port Redis is running on as well as the exposed port. This is the working Docker compose file.
version: '3.7'
services:
redis:
container_name: redis
hostname: redis
image: sameersbn/redis:4.0.9-2
command: --port 6380
ports:
- "6380:6380"
expose:
- "6380"
volumes:
- type: volume
source: redis-data
target: /data
restart: always
redis-commander:
container_name: redis-commander
hostname: redis-commander
image: rediscommander/redis-commander:latest
restart: always
environment:
- REDIS_HOSTS=local:redis:6380
ports:
- "8082:8081"
volumes:
redis-data: {}
这篇关于在Docker Compose中更改Redis端口不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!