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?

3
  • Have you tried to supply the full path to 'java'? Commented Oct 21, 2014 at 2:36
  • Did you find an answer? Commented Oct 24, 2014 at 20:35
  • @Rob3 as I told in the question, I already have a solution, but I was looking for the "best" method (how it should be done) to manage command line arguments in Docker Commented Oct 29, 2014 at 9:10

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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?
Don't think the issue is with Docker, rather how the shell processes the command line args.
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.