Dockerode - custom folder for container

131 views Asked by At

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". 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. 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

1

There are 1 answers

0
cbutler On

Do you just want to create a temporary folder? If so you can just use the fs module:

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

Not sure if this answers your question or not?