2

I want to run this command inside a container: java -jar bin/felix.jar > log.txt

If I manually do:

frog@gooseberry:~/path$ sudo docker run -it 5fe6598e0648 /bin/bash
root@9beabfb5e852:/path# java -jar bin/felix.jar > log.txt
[... program running ...]

Everything works, but if I try to launch it with:

frog@gooseberry:~/path$ sudo docker run -d 5fe6598e0648 "java -jar bin/felix.jar > log.txt"

I get the following error:

857bb5fcdbd7a315517bc9031d65b26abcaaad1fac7a29574e39a0289d0d77a3
2014/10/20 10:20:53 Error response from daemon: Cannot start container 857bb5fcdbd7a315517bc9031d65b26abcaaad1fac7a29574e39a0289d0d77a3: exec: "java -jar bin/felix.jar > log.txt": stat java -jar bin/felix.jar > log.txt: no such file or directory

I get the same error if I try to use the inverted commas '' instead of the double commas "".

I want to use commas because of > log.txt part, that otherwise would be interpreted by the terminal running on the host machine.

This answer suggest to use the -c option of /bin/bash. It bypasses the problem (and it works), but there is a solution provided by Docker to this problem? How command line arguments should be managed with the command docker run?

Community
  • 1
  • 1
Manuel Durando
  • 1,493
  • 3
  • 19
  • 30

1 Answers1

2

the '>' is getting interpreted in the local env.

This will work:

sudo docker run -d 5fe6598e0648 -c "java -jar bin/felix.jar > log.txt"

The default entrypoint is /bin/sh - you can pass the arg to this as a string with the -c option.

Docker provide the CLI option to set you own --entrypoint inline, a default in your Dockerfile ENTRYPOINT. You could set either of these to be include the -c.

Amos Folarin
  • 2,059
  • 20
  • 18
  • Thank you for your answer. The solution you suggested is the same I cited in my answer. In addition of `-c` bash option, Is there an official suggested way to manage command line arguments in Docker? – Manuel Durando Oct 29 '14 at 09:14
  • Don't think the issue is with Docker, rather how the shell processes the command line args. – Amos Folarin Oct 29 '14 at 23:45
  • 1
    We'll not sure I follow what you want (your command needs to be run by something). You have a CMD/run command and and ENTRYPOINT/--entrypoint which is what the command is passed to. the entrypoint and command are concatenated. – Amos Folarin Nov 03 '14 at 22:02