NodeJS 应用程序在容器化时停止工作 [容器中的 FTP 服务器]

2023-12-08

我正在尝试将 ftp 服务器 NodeJS 应用程序容器化。当我使用 npm 运行它时它工作正常,但当我在容器内运行它时它没有响应。

这是节点应用程序: src/index.js 文件

const FtpSvr = require ( 'ftp-srv' );

const hostname = '127.0.0.1';
const port = 21;

const ftpServer = new FtpSvr ({
url:`ftp://${hostname}:${port}`,
anonymous:true
} );

ftpServer.on('login', ({connection, username, password}, resolve, reject) =>
{
    resolve({root : "./"})

    connection.on('STOR', (error, fileName) => {
        console.log("STOR")
    });
});

ftpServer.on ( 'client-error', (connection, context, error) =>
{
    console.log ( `error: ${error}` );
});

ftpServer.listen().then(() => {console.log(`Server running at http://${hostname}:${port}/`);});

我的 package.json 文件

{
  "name": "ftp-server",
  "version": "1.0.0",
  "description": "FTP server to receive images from cameras and save them on Azure Blob storage",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node src/index.js"
  },
  "author": "Rakshak",
  "license": "ISC",
  "dependencies": {
    "ftp-srv": "4.3.4"
  }
}

我的泊坞窗文件

FROM node:12

WORKDIR /app

COPY package.json ./

RUN npm install

COPY . .

EXPOSE 20-21
EXPOSE 65500-65515

CMD ["npm", "start"]

我正在使用 FileZilla 测试 FTP 服务器。当我使用 npm start 运行服务器并使用 FileZilla 连接时

Connecting to 127.0.0.1:5000...
Status:         Connection established, waiting for welcome message...
Status:         Insecure server, it does not support FTP over TLS.
Status:         Logged in
Status:         Retrieving directory listing...
Status:         Directory listing of "/" successful

我正在使用此命令来构建 docker 映像

 docker build -t rrakshak/ftp-demo .

我用它来运行 docker

 docker run -p 5000:5000 rrakshak/ftp-demo:latest

这是 FileZilla 控制台上的消息

Connecting to 127.0.0.1:5000...
Status:         Connection established, waiting for welcome message...
Error:          Connection closed by server
Error:          Could not connect to server
Status:         Waiting to retry...
Status:         Connecting to 127.0.0.1:5000...
Status:         Connection established, waiting for welcome message...
Error:          Connection closed by server
Error:          Could not connect to server

看起来当服务器在容器内运行时,FileZilla 能够连接,但没有收到它期望的文件列表响应。

- - - - - - 更新 - - - - - - - - - - - -

将主机设置为 0.0.0。在 Filezilla 上给我一组新消息

Status:         Connecting to 127.0.0.1:21...
Status:         Connection established, waiting for welcome message...
Status:         Insecure server, it does not support FTP over TLS.
Status:         Logged in
Status:         Retrieving directory listing...
Command:    PWD
Response:   257 "/"
Command:    TYPE I
Response:   200 Switch to "binary" transfer mode.
Command:    PASV
Response:   502 Command not supported
Command:    PORT 127,0,0,1,231,209
Response:   500 The given address is not yours
Error:          Failed to retrieve directory listing

为什么我的应用程序在节点中运行时可以运行,但在容器化时却不能运行?


收听0.0.0.0:5000在容器中,定义了被动端口

const FtpSvr = require ( 'ftp-srv' );
  
const hostname = '0.0.0.0';
const port = 5000;

const ftpServer = new FtpSvr ({
  url: `ftp://${hostname}:${port}`,
  anonymous: true,
  pasv_url: `ftp://${hostname}:${port}`,
  pasv_min: 65500,
  pasv_max: 65515,
});

按原样构建容器,然后使用映射的以下端口运行,这些端口都可以在 ftp 连接中使用:

docker run -p 5000:5000 -p 65500-65515:65500-65515 --rm rrakshak/ftp-demo

给出回应:

$ curl ftp://localhost:5000
-rw-r--r-- 1 1 1          141 Oct 21 01:22 Dockerfile
drwxr-xr-x 1 1 1         4096 Oct 21 01:21 node_modules
-rw-r--r-- 1 1 1        21137 Oct 21 01:21 package-lock.json
-rw-r--r-- 1 1 1           52 Oct 21 01:21 package.json
-rw-r--r-- 1 1 1          660 Oct 21 01:23 server.js
-rw-r--r-- 1 1 1        20287 Oct 21 01:21 yarn.lock

ftp 客户端必须设置为使用被动模式。

当 FTP 客户端处于主动模式,FTP服务器收到一个PORT来自客户端的命令,并创建一个从容器返回到客户端的新 TCP 连接,以获取该连接上的数据PORT.

由于 Docker 端口映射到容器中,此数据连接的源地址通常与 FTP 客户端用作 FTP 服务器初始目标的地址不匹配。在经典服务器上设置 NAT 后面的 FTP 服务器时,会出现类似的问题。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

NodeJS 应用程序在容器化时停止工作 [容器中的 FTP 服务器] 的相关文章

随机推荐

  • 使用 Excel VBA 事件检测单元格的合并/取消合并?

    我正在尝试找到一种方法来检测合并 或取消合并 单元格的立即使用 更改事件会触发 选择也不会更改 我已经尝试过其他一些 但合并时似乎没有事件触发 我觉得很奇怪 我在更改事件中的代码当前根据单元格的内容更改 Interior Color 如果单
  • ASP:我无法将某些字符从 utf-8 解码为 iso-8859-1

    我用这个函数来解码UTF 8 function DecodeUTF8 s dim i dim c dim n i 1 do while i lt len s c asc mid s i 1 if c and H80 then n 1 do
  • tidyr - 获得组合的独特方式(仅使用 tidyverse)

    我想使用以下方法获取数据帧的唯一字符串列的所有唯一成对组合tidyverse 理想情况下 这是一个虚拟示例 library tidyverse a lt letters 1 3 gt tibble as tibble a gt A tibb
  • 中缀数据构造运算符的解释

    我正在阅读这篇有趣的博客文章 名为解析 不验证它包括 为此 我们需要一个表示非空列表的类型 幸运的是 Data List NonEmpty 中现有的 NonEmpty 类型正是如此 它有以下定义 data NonEmpty a a a 请注
  • Perl 错误地抱怨名称“main::FILE”仅使用一次

    我将程序简化为以下小片段 但我仍然收到消息 名称 main FILE 仅使用一次 可能有拼写错误 usr bin perl w use strict use autodie qw open close foreach my f ARGV l
  • VBA根据形状选择形状

    How do I select all shapes array range where the value in Cell A Shape TopLeftCell Row 0 阵列应仅包含形状 2 和 3 如上图所示 作为替代方案 您可以
  • @class我可以知道这个的正确用法吗

    任何人都可以使用 class 指出文档或详细讨论 我一直在使用这个 但还没有真正完全理解它 我想更多地了解它并充分理解它 先感谢您 class习惯于declare一类 本质上是告诉编译器 嘿 有一个具有这个名称的类某处在源代码中 定义稍后会
  • 由于 ____chkstk_darwin,在 Catalina 上使用 Deployment 10.10 编译的 MacOS 应用程序在 < HighSierra 版本上崩溃

    我们有一个多平台桌面应用程序 它使用用 C 编写的通用组件 该组件使用 OpenSSL 和 PocoProject 两者都静态链接到库中 在 macOS 上 我们有一个用 Objective C 编写的小型框架 它本质上是 C 代码的单个
  • Java ImageIO:无法读取输入文件

    我不知道为什么这不起作用 但程序说它无法读取输入文件 顺便说一句 这也在 Ubuntu 中运行 这是示例代码 URI url new URI images GUI TitleScreen PNG File file new File url
  • 如何使用javascript找到浏览器的高度,包括工具栏和按钮?

    有没有办法通过浏览器的工具栏和按钮来查找浏览器高度 而不仅仅是窗口或文档高度 对于视口的大小 您可以使用window innerWidth and window innerHeight 对于整个窗户 包括装饰 使用window outerW
  • 如何设置div的高度相同

    这是我的情况 HTML div div div class empty nbsp div div class empty nbsp div div class empty nbsp div div div div class empty n
  • 如何在 T-SQL 中将多行作为单行返回?

    几个月前 我们的供应商向我们的票务系统添加了一项功能 使我们可以向票证添加任意数量的自定义字段 我想将这些字段与其他调用信息一起查询以用于报告目的 但每个可扩展字段都作为一行存储在数据库中 所以基本上你有这样的东西 ext doc no c
  • 按需初始化持有者习语 - 何时加载类?

    我一直在看 https en wikipedia org wiki Initialization on demand holder idiom了解更多有关单例的信息 我的问题是静态内部类到底什么时候加载以及什么时候初始化 我的理解是 可以加
  • 使用斯坦福 CoreNLP 进行共指解析

    我是斯坦福 CoreNLP 工具包的新手 并尝试将其用于解决新闻文本中的共指问题的项目 为了使用斯坦福 CoreNLP 共指系统 我们通常会创建一个管道 这需要标记化 句子分割 词性标记 词形还原 命名实体识别和解析 例如 Properti
  • 我不明白 EF5 dbContext.Entry(entity).Reload() 方法应该如何工作?

    在这个例子中 using System using System Collections Generic using dbModel using System Linq using System Data Entity Infrastruc
  • 带有 MAMP Pro 的自动虚拟主机?

    使用 MAMP Pro 您可以创建诸如 local example com 之类的条目 并指向本地计算机上该站点的根目录 是否可以将其自动化 在我的电脑上 我的设置如下 用户 hm Sites example com app 用户 hm S
  • Brainfuck 尝试 - 在 0 细胞中

    如果我尝试在包含 0 的单元格中输入 在 Brainfuck 中会发生什么 gt 另外 如果我尝试在指向 0 单元格时启动循环 会发生什么情况 gt 编辑 我忘了提 但我正在努力做一名翻译 这是我用作示例的一段代码 gt lt gt lt
  • 在我的页面中有效加载 CSS

    这是我的问题 我正在使用 Google Page Speed Insights 分析我的页面 它告诉我删除头部 浮动线上方 的 css 链接 因为它阻止了我的页面加载 现在我的文档头部有一个简单的链接 我尝试将链接行放在文档的底部 就在页面
  • 使用 range-v3 读取逗号分隔的数字列表

    我想使用范围 我使用 range v3 实现 来读取输入流 该输入流是逗号分隔的数字列表 如果没有范围 这是微不足道的 但是 这就是我认为解决这个问题的直接方法 auto input std istringstream 42 314 11
  • NodeJS 应用程序在容器化时停止工作 [容器中的 FTP 服务器]

    我正在尝试将 ftp 服务器 NodeJS 应用程序容器化 当我使用 npm 运行它时它工作正常 但当我在容器内运行它时它没有响应 这是节点应用程序 src index js 文件 const FtpSvr require ftp srv