更新
我想我需要使用.run而不是.createContainer
但是,我不知道如何将docker容器绑定到我的cwd。
docker.run("wpscanteam/wpscan", [
// "--mount",
// "type=bind,source=" + process.cwd() + "/docker-bind,target=/output",
// "-o",
// "/output/wpscan-output.json",
"--format",
"json",
"--url",
"https://example.com/",
], process.stdout, function (err, data, container) {
console.log(data.StatusCode);
})如果未注释的Scan Aborted: invalid option: --mount,注释行(2-6)会导致错误。
我可以添加这些创建参数,我认为我需要使用volume,但我不确定。
OG Post
我试图使用克罗德来执行这个docker命令docker run --rm --mount type=bind,source=$HOME/docker-bind,target=/output wpscanteam/wpscan:latest -o /output/wpscan-output.json --format json --url 'https://example.com/'
下面是我尝试过的,但是当我运行时,这使容器使用正确的命令,但是它(几乎)立即退出,并且当我docker container inspect创建的contatiner时,它没有挂载的卷
我不确定Mount是否是我应该使用的正确参数,但我不认为这是问题所在,因为停靠实例停留在<.5秒,当我在WSL中运行命令时,运行该命令需要大约10秒的时间,所以我认为我的cmd:[]参数不会被执行。
docker.createContainer({
Image: 'wpscanteam/wpscan',
AttachStdin: false,
AttachStdout: true,
AttachStderr: true,
Mounts:
[
{
"Type": "bind",
"Source": process.cwd() + "/docker-bind",
"Destination": "/output",
}
],
Tty: false,
Cmd: [
"-o",
"/output/wpscan-output.json",
"--format",
"json",
"--url",
"https://example.com/"
],
OpenStdin: false,
StdinOnce: false
}, (err, container)=>{
container.start(function (err, data) {
console.log(data)
console.log(err)
})
})当我在WSL 2中运行这个命令docker run --rm --mount type=bind,source=$HOME/docker-bind,target=/output wpscanteam/wpscan:latest -o /output/wpscan-output.json --format json --url 'https://example.com/'时,它完美地将JSON放置在我磁盘上的docker文件夹中。
在将此命令转换为dockerode时,我使用了process.cwd()而不是$HOME,因为$HOME是WSL特性。(我的项目目录中也有docker-bind文件夹,这样就不会有问题了)
我是相当有经验的码头,但这是我的专长以外的方式。
dr有一个docker命令,需要将输出放在项目目录中的文件夹中。它需要能够使用Node.js运行。
如果有一个更好的图书馆得到良好的支持,请告诉我。
码头文档为您提供方便(1.42)
发布于 2021-02-28 10:34:09
这就是我用来回答的
docker.run("wpscanteam/wpscan", [
"-o",
"/output/wpscan-output.json",
"--format",
"json",
"--url",
"https://example.com/",
], process.stdout, {
HostConfig:{
Binds:[
process.cwd() + "/docker-bind:/output"
]
}
}, function (err, data, container) {
console.log(data.StatusCode);
}
)https://stackoverflow.com/questions/66407498
复制相似问题