'terminal command is running inside docker container but the same command is not running from local machine

Running docker container in iterative mode

  • Files present inside the cpp_test directory in docker container:

    root@ad2d85985536:/usr/src/cpp_test# ls

    core input input.txt main test.cpp

  • Running execution command (c++ file) inside the docker container through iterative CLI:

    root@ad2d85985536:/usr/src/cpp_test# ./main <input.txt>output1.txt

    root@ad2d85985536:/usr/src/cpp_test# ls

    core input input.txt main output1.txt test.cpp

As you can see the output1.txt file is created.

  • But if I run the same command from my local machine terminal using the docker exec command my execution doesn't work. As shown below:

    ┌──(legion㉿kali)-[~/dev/OJ/docker] └─$ docker exec --workdir /usr/src/cpp_test checker ./main.exe < input.txt > output1.txt

    zsh: no such file or directory: input.txt

I get the error as no such file is present. But when I try to access the input.txt file using the same docker exec command I can access it without any problem.

Please help!!!



Solution 1:[1]

Is that all one command line? You're redirecting input to the docker command from input.txt? That's probably not what you want, as input.txt is inside the container. Did you include quotes so the input and output redirection becomes part of the command?

As written, that command is akin to:

docker < input.txt ... a bunch of options ...

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Joseph Larson