如何解决将运行 NestJS 并配置 Bull 的 Lightsail 容器与另一个带有 Redis 的 Lightsail 容器连接起来
我正在 NestJS 中执行一个服务器端应用程序,该应用程序将 Bull 配置为连接到 Redis 以获取队列。为此,我遵循了 NestJS 的官方文档here。
在本地,我有 2 个 Docker 容器,一个用于 NestJS 应用程序,另一个用于 Redis。使用主机 localhost
和端口 6379
在它们之间建立连接,一切正常。
当我尝试使用 Redis 在 Amazon AWS Lightsail Containers 上运行 Docker 容器并尝试连接到它时,我的问题就开始了。
在 Amazon AWS Lightsail Containers 上,我有两个容器:
- 在生产模式下运行的 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 上。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。