문제

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?

도움이 되었습니까?

해결책

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

다른 팁

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

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top