3

I'm trying to execute lein run in a Clojure Docker image out of a mounted folder that is not /, but when I try to cd into a folder, Docker complains with unable to locate cd:

docker run -v /root/chortles:/test -i jphackworth/docker-clojure cd /test && lein run
=> Unable to locate cd

How do I instruct Leiningen to run in a different folder, or tell Docker to change the directory prior to running my command?

Petrus Theron
  • 27,855
  • 36
  • 153
  • 287
  • It looks like your problem is that "cd" is not a program (and can't be: it would have to change the working directory of its parent process). Rather, it's a shell builtin. I don't know docker, so I don't know what the solution is. – Max Feb 22 '14 at 11:06

3 Answers3

8

You can use -w param for docker run. This parameter is useful for specifying working directory within container.

docker run -w /test -v /root/chortles:/test -i jphackworth/docker-clojure lein run
Jiri
  • 16,425
  • 6
  • 52
  • 68
0

The best bet is to add a shell script to the docker image and call that.

Have a script called, say lein-wrapper.sh, install in in /usr/local/bin. The script should sort out the environment for leiningen and then call it. Something like this:

#!/bin/sh
export PATH=${LEININGEN_INSTALL}:${PATH}
cd /test
lein $@

You can set

ENTRYPOINT["/usr/local/bin/lein-wrapper.sh"]

In your Dockerfile

And invoke it as:

# Will call /usr/local/bin/lein-wrapper.sh run 
# which will call lein run   
docker run -v /root/chortles:/test -i jphackworth/docker-clojure run

# or run lein deps...
docker run -v /root/chortles:/test -i jphackworth/docker-clojure deps
sw1nn
  • 7,278
  • 1
  • 26
  • 36
0

cd is a bash builtin, not a command. You can use bash -c 'cd /test && lein run'. Better yet, do as @Jiri states and use the -w parameter to set the working directory of the container, then just use lein run to start your app.

Ben Whaley
  • 32,811
  • 7
  • 87
  • 85