I have a gcc container that compiles a piece of code and gives me the output. The code that has to be run within the container has a "cin>>" to read the input from the terminal. I am using dockerode for the application and the code, input to the code is passed from the frontend.
const containerConfig = {
Image: gcc
Cmd: [
"bash",
"-c",
`echo "${code}" > myapp.cpp && g++ -o myapp myapp.cpp && ./myapp`,
];
Tty: true,
};
const container = await docker.createContainer(containerConfig);
I am able to parse the output from the logs after the code is run in the container. Is there any way so that I can pass the input to my code that is run within the container? One way of doing it is instead of using a "cin>>" I can directly append the input parameters in the string "code" used in echo. I dont think it is an efficient or correct approach. I am trying to learn docker and any improvement over the existing method is appreciated.