Reputation: 3956
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
Upvotes: 0
Views: 3847
Reputation: 3956
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
Upvotes: 1
Reputation: 1323115
It would be easier to:
entrypoint.sh
with your command logic scripted in it.COPY
that file in your DockerfileCMD
undefinedThat 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.
Upvotes: 2