目前,我正试图开发一个小后端,以证明自己的概念。我正在使用docker连接数据库redis和快递服务器。一切正常,除了我无法连接到我的redis服务器,如果我使用密码进行身份验证。
看看我的船坞-合成人:
version: '3.8'
volumes:
portfolio-data:
portfolio-cache:
services:
database:
image: mongo
restart: always
environment:
- MONGO_INITDB_ROOT_USERNAME=$MONGODB_ROOT_USERNAME
- MONGO_INITDB_ROOT_PASSWORD=$MONGODB_ROOT_PASSWORD
volumes:
- portfolio-data:/data/db
ports:
- 27017:27017
redis:
image: redis
restart: always
ports:
- 6379:6379
volumes:
- ./config/redis.conf:/etc/redis/redis.conf
- portfolio-cache:/data
command: ["redis-server", "/etc/redis/redis.conf"]
portfolio-api:
image: portfolio-api
depends_on:
- database
- redis
env_file: ./.env
environment:
- API_PORT=8000
- DB_HOST=$MONGO_HOST
- DB_PORT=27017
- DB_USER=$MONGO_USER
- DB_PASSWORD=$MONGO_PASSWORD
- REDIS_HOST=$REDIS_HOST
- REDIS_PASSWORD=$REDIS_PASSWORD
- REDIS_PORT=6379
- REDIS_SECRET=$REDIS_SECRET
volumes:
- .:/app
ports:
- 8000:8000当然,redis服务就是redis服务器。我使用了标准的redis.conf,其中我将所需的密码更改为我选择的密码。在这里,我连接到我的redis服务器:
const redis = new Redis({
host: redisConfig.host,
port: redisConfig.port,
password: redisConfig.password
});
redis.on('error', (err: Error) => {
backendLogger.error(err.message);
});
redis.on('connect', () => {
backendLogger.info('Connected successfully to redis');
});此代码段的输出为:
2022-09-28T06:46:29.707Z error: connect ECONNREFUSED <ip>我可以用密码从redis客户端连接到redis服务器。没有配置文件,通过IORedis的连接就像预期的那样工作,例如我接收输出:
Connected successfully to redis如果我传递配置文件并通过密码进行身份验证,有人知道为什么拒绝连接吗?
发布于 2022-10-06 13:22:45
对于那些感兴趣的人,这个问题与我的Redis配置文件有关。由于某些原因,默认的https://download.redis.io/redis-stable/redis.conf不适用于我和我的码头容器,我使用了一个来自一个好友的定制版本,这个版本最终成功了。不幸的是,我不知道到底是哪个设置导致了错误。如果相关,我可以将副本链接到工作的redis.conf文件。
https://stackoverflow.com/questions/73877516
复制相似问题