I need to run an application from a specific directory.
$ sudo docker run -P ubuntu/decomposer 'cd /local/deploy/decomposer; ./decomposer-4-15-2014'
2014/10/09 21:30:03 exec: "cd /local/deploy/decomposer; ./decomposer-4-15-2014": stat cd /local/deploy/decomposer; ./decomposer-4-15-2014: no such file or directory
That directory definitely exists, and if I connect to docker by running bash interactively I can run the above command.
$ sudo docker run -i -t ubuntu/decomposer /bin/bash
# cd /local/deploy/decomposer; ./decomposer-4-15-2014
I can run my program by specifying the full path, but then it crashes as it expects to be launched from the current directory. What can I do?
cd
is not a command - but a shell built-in - ie. you need to run ashell
first. ie. theexec
'ed command did not exist, not the directory. Quoting everything passed to the container breaks things - ie. the whole line will be treated as the command toexec
', rather than the first item, with the remaining being passed as arguments toexec
'ed command. Hence:docker run --rm alpine '/bin/sh -c cd /etc; ls -l'
- will fail. While:docker run --rm alpine /bin/sh -c 'cd /etc; ls -l'
- will succeed. And:docker run --rm alpine /bin/sh -c cd\ /etc\;\ ls\ -l
- will also succeed.