I want to send some java code as a string to an API to then run it in a docker container and return the console output, I have managed to do it with Python but as java first needs to be compiled then ran I'm unsure how to implement the language.
currently using the python image but I am not too familiar with java and im unsure how to approach it.
my environment is node using typescript and im using the dockerode module.
let container = await docker.createContainer({
Image: 'python',
Tty: true,
Cmd: ['/bin/bash'],
StdinOnce: true
});
I'm able to pass the string directly to the container by adding it to the Cmd after running python but not sure how I would pass a string into a file then compile and run it.
var options = {
Cmd: ['python', '-c'],
AttachStdout: true,
AttachStderr: true,
};
options.Cmd.push(code);
let exec = await container.exec(options);
I just have a listener to capture the output stream which can be used for later
stdout.on('data', (chunk: any) => {
let data = chunk.toString('utf8').split(/\r?\n/).filter((str: string) => {return str.length});
output = data;
})
any advice on which image to use along with how to pass the code through to get the output would be appreciated.