简体   繁体   English

Dockerode - 容器的自定义文件夹

[英]Dockerode - custom folder for container

Since yesterday, I have been trying to make a separate folder for each container in the "folder" folder in node.js api using the docker Library called "dockerode".从昨天开始,我一直在尝试使用名为“dockerode”的 docker 库在 node.js api 的“文件夹”文件夹中为每个容器创建一个单独的文件夹。 Unfortunately, I did not find any good solution that would work.不幸的是,我没有找到任何可行的好解决方案。 I looked at the Pterodactyl Daemon (old) source code where they had it, but unfortunately it didn't work for me either.我查看了他们拥有的 Pterodactyl Daemon(旧)源代码,但不幸的是它对我也不起作用。 Do you know of any good solutions that could work well?你知道有什么好的解决方案可以很好地工作吗?

If you need any more info, I will write it for you here.如果您需要更多信息,我会在这里为您写。

Have a nice rest of the day, Domi Domi,今天有一个不错的 rest

Do you just want to create a temporary folder?您只想创建一个临时文件夹吗? If so you can just use the fs module:如果是这样,您可以使用 fs 模块:

const fs = require('fs');


exports.createTmpDir = (dir) => {
  if (!fs.existsSync(dir)) {
    fs.mkdirSync(dir, { recursive: true });
  }
};

exports.generateRandomString = (length = 15) => {
  return Math.random().toString(36).substring(2, length);
};

you can use it like this:你可以像这样使用它:

// assume you call it from the root project directory
const root = ${process.cwd()}`;

// create a temp folder path. use this if you want to clean up later.
const tempDir = `${root}/tmp/${generateRandomString()}`;
createTmpDir(tempDir);

You can also use fs to copy or move your dockerfile in to that folder您还可以使用 fs 将 dockerfile 复制或移动到该文件夹中

Not sure if this answers your question or not?不确定这是否回答了您的问题?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM