Running a Docker Image Command in an Installed Folder

I try to execute lein runin a Clojure Docker image from an installed folder that is not /, but when I try cdto a folder, Docker complains about 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 work in a different folder or tell Docker about directory changes before running my command?

+3
source share
3 answers

You can use the parameter -wfor docker run. This parameter is useful for specifying the working directory in the container.

docker run -w /test -v /root/chortles:/test -i jphackworth/docker-clojure lein run
+7
source

It is best to add a shell script to the docker image and invoke it.

script, lein-wrapper.sh, /usr/local/bin. script leiningen, . - :

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

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

Dockerfile

:

# 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
0

cdis a bash builtin , not a command. You can use bash -c 'cd /test && lein run'. Even better, as @Jiri claims and uses the option -wto set the container's working directory, then just use it lein runto launch your application.

0
source

All Articles