You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Gramjs client.start()本地运行正常但Docker容器中卡住的问题求助

Gramjs client.start()本地运行正常但Docker容器中卡住的问题求助

我正在部署一个基于 NodeJS Gramjs(Python Telethon 的 NodeJS 移植版本)的应用,本地测试时 Gramjs 能毫无问题地连接到 Telegram 账号,但在 Docker 容器中测试时,虽然能成功建立连接,但之后就卡住不动了。

容器运行日志:

[2024-02-10T10:05:41.294] [INFO] - [Running gramJS version 2.19.9]

[2024-02-10T10:05:41.311] [INFO] - [Connecting to 91.108.56.132:80/TCPFull...]

[2024-02-10T10:05:41.313] [DEBUG] - [Connecting]

[2024-02-10T10:05:41.332] [DEBUG] - [Finished connecting]

[2024-02-10T10:05:41.334] [DEBUG] - [Connection success!]

[2024-02-10T10:05:41.334] [DEBUG] - [Already have an auth key ...]

[2024-02-10T10:05:41.334] [DEBUG] - [Starting send loop]

[2024-02-10T10:05:41.335] [DEBUG] - [Waiting for messages to send... false]

[2024-02-10T10:05:41.335] [DEBUG] - [Starting receive loop]

[2024-02-10T10:05:41.336] [DEBUG] - [Receiving items from the network...]

[2024-02-10T10:05:41.337] [INFO] - [Connection to 91.108.56.132:80/TCPFull complete!]

[2024-02-10T10:05:41.358] [INFO] - [Using LAYER 166 for initial connect]

[2024-02-10T10:05:41.364] [DEBUG] - [Send InvokeWithLayer]

[2024-02-10T10:05:41.369] [DEBUG] - [Assigned msgId = 7333912386031770884 to InvokeWithLayer]

[2024-02-10T10:05:41.371] [DEBUG] - [Got 1 message(s) to send]

[2024-02-10T10:05:41.372] [DEBUG] - [Encrypting 1 message(s) in 100 bytes for sending]

[2024-02-10T10:05:41.375] [DEBUG] - [Sending   InvokeWithLayer]

[2024-02-10T10:05:41.386] [DEBUG] - [Encrypted messages put in a queue to be sent]

[2024-02-10T10:05:41.386] [DEBUG] - [Waiting for messages to send... false]

日志到这里就停滞不动了。

我的代码文件:

bot.example.js

const { TelegramClient } = require("telegram");
const { StoreSession } = require("telegram/sessions");
const input = require("input");
require('dotenv').config();

const client = new TelegramClient(new StoreSession("my_session"), parseInt(process.env.API_ID), process.env.API_HASH, {
  connectionRetries: 5,
});

client.setLogLevel("debug");

(async () => {
  await client.start({
    phoneNumber: async () => await input.text("Please enter your number: "),
    password: async () => await input.text("Please enter your password: "),
    phoneCode: async () => await input.text("Please enter the code you received: "),
    onError: (err) => console.log(err),
  });
  console.log("You should now be connected.");
  await client.sendMessage("me", { message: "test" });
  console.log("Sent to me.");
})()

Dockerfile

FROM node:18-alpine

WORKDIR /bot

COPY ../bot.example.js ../package.json .
COPY ../my_session ./my_session

ENV API_ID=<hidden> \
    API_HASH=<hidden>

RUN npm install

CMD [ "node", "bot.example.js" ]

我已经确保把my_session文件夹复制到了镜像中,这样就不需要重新进行认证了。如前所述,本地运行时一切正常,能成功给自己发送测试消息,但在Docker容器里就会卡住。

有没有大佬能帮忙排查一下问题?提前感谢大家的帮助!


备注:内容来源于stack exchange,提问作者Francesco

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.20 06:18:06