从 Docker 容器内的 NodeJS 连接到 Windows 网络共享驱动器

Connecting to Windows Network Share Drive from NodeJS inside Docker Container

我一直在为此苦思冥想,希望得到任何帮助!我确实进行了搜索,并找到了一些可能的解决方案,但对我来说都是不行的。

我有一个在 windows 中开发的 nodejs 应用程序,现在 运行 正在 docker 容器中(使用 node:latest 图像)。该应用程序需要连接到共享 windows 网络驱动器才能执行 read/writes,但当应用程序 运行 位于 docker 容器中时它似乎无法正常工作(当它在 docker 之外的我的 windows 机器上 运行 时,它工作正常。

网络驱动器共享文件夹看起来像这样。分享给大家:

\\myserver\test

Nodejs 代码(不完全但是让您了解我是如何访问文件的):

let fileLocation = "\myserver\test\file.pdf"
let readStream = fs.createReadStream(fileLocation)

// When the stream is done being read, end the response
readStream.on('close', () =>
{
    // End response
    response.status('200').end()

    // Remove the file
    fs.unlinkSync(fileLocation)
})

// Stream chunks to response
readStream.pipe(response)

当 运行 在 windows 上的 nodejs 中时,这工作正常,但是当 运行 在 nodejs docker 容器中时,我不断收到 "ENOENT: no such file or directory" 错误。我不确定这是 linux OS(节点图像所基于的)还是 docker permission/priviledge 问题。该文件确实存在。

这是我在运行安装容器

时用来测试的命令
docker run --rm -it -p 8080:8080 myapplication:latest

docker 的新手,但如有任何帮助,我们将不胜感激!

尝试使用 docker run -v 安装卷(参见 documentation)。

我希望它能在您的 Windows 网络共享驱动器上运行。

更新

Windows 中卷安装的语法是: docker run -v c:/Users:/data alpine

其中 c:/Users 是您要挂载的主机上的 Windows 目录(相当于 Windows 语法中的 C:\Users),data 是运行 容器内的挂载目录。