【问题标题】:NodeJS and SQL Server : unable to connect when in a Docker ContainerNodeJS 和 SQL Server:在 Docker 容器中时无法连接
【发布时间】:2021-10-19 13:21:17
【问题描述】:

我有一个 NodeJS 应用程序,在服务器上独立运行时运行良好。当我在 docker 容器中运行它时,它会显示以下错误消息:

ConnectionError: 无法连接到 TEXTREPLACED:undefined - socket hang up

在 /app/node_modules/mssql/lib/tedious/connection-pool.js:71:17
在 Connection.onConnect (/app/node_modules/tedious/lib/connection.js:1037:9)
在 Object.onceWrapper (node:events:514:26)
在 Connection.emit (node:events:394:28)
在 Connection.emit (/app/node_modules/tedious/lib/connection.js:1065:18)
在 Connection.socketError (/app/node_modules/tedious/lib/connection.js:1663:12)
在 Connection.socketEnd (/app/node_modules/tedious/lib/connection.js:1693:12)
在套接字。 (/app/node_modules/tedious/lib/connection.js:1433:14)
在 Socket.emit (节点:事件:406:35)
在 endReadableNT(节点:内部/流/可读:1331:12){
代码:'ESOCKET',
originalError: ConnectionError: 无法连接到 TEXTREPLACED:undefined - socket hang up
在 ConnectionError (/app/node_modules/tedious/lib/errors.js:13:12)
在 Connection.socketError (/app/node_modules/tedious/lib/connection.js:1663:56)
在 Connection.socketEnd (/app/node_modules/tedious/lib/connection.js:1693:12)
在套接字。 (/app/node_modules/tedious/lib/connection.js:1433:14)
在 Socket.emit (节点:事件:406:35)
在 endReadableNT(节点:内部/流/可读:1331:12)
在 processTicksAndRejections (node:internal/process/task_queues:83:21) {
代码:'ESOCKET'
}
}

我的连接代码是:

const sqlConfig = {
        user: 'LOGIN',
        password: 'PASSWORD',
        server: 'SERVER\\INSTANCE',
        database: 'DATABASE',
        debug:true,
        port: 1433,
        driver:'tedious',
        pool:{
                idleTimeoutMillis: 1000
        },
        options:{
                port:1433,
                enableArithAbort:true,
                encrypt:true,
                trustServerCertificate:true,
                instanceName:'INSTANCE',
                database:'DATABASE',
                debug:{
                        packet: true,
                        data:true,
                        payload:true,
                        token:true,
                        log:true
                }
        }
};

const global_pool = new sql.ConnectionPool(sqlConfig);
var global_pool_con = null;

try {
        global_pool_con = global_pool.connect();
}catch{
        console.log(err);
}

Dockerfile

# Use Node base image 
FROM node:latest 
#ports 
EXPOSE 3000 
EXPOSE 1433 
WORKDIR /app 
COPY package.json /app 
RUN npm install 
COPY . /app 
USER node
CMD [run, script, release]

“发布”脚本运行初始 js 文件。

令人困惑的是,错误显示“未定义”而不是端口号。我已经使用了主机和网桥连接以及路由的端口 1433 和 3000 (HAPI),并确认端口已在 dockerfile 中公开。

考虑到它在独立时可以工作,我假设是某个 docker 设置导致了问题。

更新:正在发送 TLS/SSL 协商数据包但未收到

State change: SentPrelogin -> SentTLSSSLNegotiation

更新:当 dockerised 应用程序尝试连接时,SQL Server 会在事件日志中显示此错误。

A fatal alert was generated and sent to the remote endpoint. This may result in termination of the connection. The TLS protocol defined fatal error code is 40. The Windows SChannel error state is 1205.

An TLS 1.2 connection request was received from a remote client application, but none of the cipher suites supported by the client application are supported by the server. The SSL connection request has failed.

【问题讨论】:

  • 当使用容器时,您只在尝试连接到容器本身时打开\路由容器周围的端口,如果使用桥接网络或共享主机的网络设置,您应该能够访问所有内容你的主机可以。另外,显示未定义的错误是什么,您是否也可以包含它?可能是您错误地配置了 docker 网络设置,您在什么操作系统和版本上安装了 docker 以及如何安装?
  • server: 'SERVER\\INSTANCE'port: 1433?您是否尝试过删除实例名称(从您使用它的两个地方)?当客户端连接字符串中涉及实例名称时,需要 SQL Server Browser 服务将实例名称解析为 TCP 端口号 - 并且浏览器服务本身会侦听 udp/1434,这是您无法从 Docker 容器公开/发布的内容.
  • 您是否尝试从容器中访问server\instanceserver\instance 是另一个容器还是在主机上?
  • @NoamYizraeli 错误消息是帖子中的第一个代码片段,第一行应为 : 但端口号显示为未定义,即使它已经定义? Docker 在 Ubuntu Server 20.4 上运行,安装从 Docker 网站开始
  • @AlwaysLearning 我已经尝试将两者都删除,恐怕没有运气。我正在运行浏览器服务。

标签: node.js sql-server docker tedious


【解决方案1】:

感谢大家的帮助。

解决方法是更新 openSSL.cnf 文件,其中包含来自源图像的其他不需要的行。

【讨论】:

    猜你喜欢
    • 2019-05-29
    • 2016-12-26
    • 2017-08-10
    • 2019-11-19
    • 2022-01-04
    • 2020-06-12
    • 1970-01-01
    • 2017-06-07
    • 2021-10-10
    相关资源
    最近更新 更多