【发布时间】:2021-03-07 19:53:04
【问题描述】:
我正在 NestJS 中做一个服务器端应用程序,它配置 Bull 以连接到 Redis 以进行队列。为此,我遵循了 NestJS 的官方文档here。
在本地,我有 2 个 Docker 容器,一个用于 NestJS 应用程序,另一个用于 Redis。使用主机localhost 和端口6379 建立它们之间的连接,一切正常。
当我尝试使用 Redis 在 Amazon AWS Lightsail Containers 上运行 Docker 容器并尝试连接到它时,我的问题就开始了。
在 Amazon AWS Lightsail 容器上,我有两个容器:
- NestJS 应用在生产模式下运行。
- 使用默认设置的 Redis。
在我的 Redis 容器的配置中,我通过 TCP 打开了 6379 端口。在我的 NestJS 容器的配置中,我做了同样的事情。
Lightsail 上的所有容器都有一个公共域和一个私有域。我已经使用私有域作为主机传递给 Bull 配置,例如:
createSharedConfiguration(): Promise<Bull.QueueOptions> | Bull.QueueOptions {
return {
redis: {
host: my-redis.service.local, // <- Private domain of my Redis container
port: 6379,
},
};
}
当我将 NestJS 应用部署到其容器时,我会在控制台中收到以下信息:
(node:17) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)
(node:17) UnhandledPromiseRejectionWarning: Error: connect ETIMEDOUT
at Socket.<anonymous> (/app/node_modules/ioredis/built/redis/index.js:308:37)
at Object.onceWrapper (events.js:421:28)
at Socket.emit (events.js:315:20)
at Socket._onTimeout (net.js:483:8)
at listOnTimeout (internal/timers.js:554:17)
at processTimers (internal/timers.js:497:7)
NestJS 似乎尝试连接,但他不能,我不知道为什么。
我错过了什么?
我的目标是将一个容器中的服务器端应用程序连接到另一个装有 Redis 的容器。两个容器都在Amazon AWS Lightsail Containers。
【问题讨论】:
标签: redis nestjs amazon-lightsail