我的任务是创建Dockerfile
,使其按以下方式工作:
docker build -t test .
返回Image named test successfully created
docker run --rm test
返回Hello world!
docker run --rm test Universe
返回Hello Universe!
到目前为止我所拥有的:
的 Dockerfile
FROM ubuntu:14.04
LABEL maintainer="trthhrtz"
CMD if [ $# -eq 0 ]; then echo "Hello world!"; else echo "Hello " + $@ + "!"; fi
在输入参数的情况下它不起作用,错误是:
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
答案 0 :(得分:2)
更容易:
entrypoint.sh
。COPY
that file CMD
undefined 这样,docker run -it --rm myImage arg1 arg2 ...
命令的任何其他参数都将传递给bash entrypoint.sh脚本,该脚本将正确解释$@
,如“What does set -e
and exec "$@"
do for docker entrypoint scripts?”所示。登记/>
有关详情,请参阅“Passing arguments from CMD in docker”。
答案 1 :(得分:1)
执行docker command
时,请确保参数顺序正确。
例如:
docker run --name test-ubuntu -it d37f4165b5d2 bash
代替
docker run --name test-ubuntu d37f4165b5d2 -it bash