7

I am developing a lib for docker command line in nodejs, I am still in starting face, I just tried basic docker run command using spawn in node js - everything works fine but it's not working for complex cases like the one below.

I want to run docker run --rm -it julia:0.3.6 julia -E "[x^2 for x in 1:100]" in nodejs, but I am gettting below error -

the input device is not a TTY

Docker Shell existed with status = 1

Below Code -

    const
        spawn = require('child_process').spawn,
        dockerDeamon = spawn("docker", ["run","--rm", "-it", "julia:0.3.6", "-E",   "\" [x^2 for x in 1:100]\""] );

    dockerDeamon.stdout.on('data', data => {
        console.log(`${data}`);

    });

    dockerDeamon.stderr.on('data', data => {
        console.log(`${data}`);

    });

    dockerDeamon.on('close', code => {
        console.log(`Docker Shell existed with status = ${code}`);

    });

Is there any better way to execute the above script ?

1 Answer 1

7

You're passing the -t (--tty) flag to Docker, which tells it that it should expect the input and output to be attached to a terminal (TTY). However, when you're using spawn, you're instead attaching it to a Node.js stream in your program. Docker notices this and therefore gives the error Input device is not a TTY. Therefore, you shouldn't be using the -t flag in this case.


Also, note that you don't need nested quotes in your last argument, "\" [x^2 for x in 1:100]\"". The purpose of the quotes is to preserve the spaces and other special characters in the argument when running in a shell, but when you use spawn you're not using a shell.

So your statement should be something like:

dockerDeamon = spawn("docker", ["run","--rm", "-i", "julia:0.3.6", "julia", "-E", "[x^2 for x in 1:100]"] );
Sign up to request clarification or add additional context in comments.

2 Comments

I am trying this, but getting ` starting container process caused "exec: \"-E\": executable file not found in $PATH"` for above command.
@Sam That's because what's immediately following the image name should be the command name, which you're missing (the command arguments are directly after the image name). You should be able to just add the command name "julia" in between "julia:0.3.6" and "-E". I have updated the command in my answer to reflect this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.