简体   繁体   中英

Docker starting container process caused “exec: \”arg\“: executable file not found in $PATH”: unknown.

My task is to create Dockerfile such that it works the following way:

docker build -t test .
Returns Image named test successfully created

docker run --rm test
Returns Hello world!

docker run --rm test Universe
Returns Hello Universe!

What I have so far:
Dockerfile

FROM ubuntu:14.04

LABEL maintainer="trthhrtz"

CMD if [ $# -eq 0 ]; then echo "Hello world!"; else echo "Hello " + $@ + "!"; fi

It does not work in case of input arguments, the error is:
docker: Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \\"Universe\\": executable file not found in $PATH": unknown.
ERRO[0000] error waiting for container: context canceled

It would be easier to:

  • define an entrypoint script entrypoint.sh with your command logic scripted in it.
  • COPY that file in your Dockerfile
  • leave CMD undefined

That way, any additional parameter to your docker run -it --rm myImage arg1 arg2 ... command will be passed to the bash entrypoint.sh script, which will interpret $@ correctly, as illustrated in " What does set -e and exec "$@" do for docker entrypoint scripts? ".
See " Passing arguments from CMD in docker " for more.

Make sure you have a correct order of arguments when you do docker command .

For example:

docker run --name test-ubuntu -it d37f4165b5d2 bash
instead of
docker run --name test-ubuntu d37f4165b5d2 -it bash

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM