无法使用docker run将命令行参数传递给Shell脚本文件

时间:2017-12-14 11:21:02

标签: shell docker parameters server runtime-error

使用的命令:

sudo docker run -it -p 80:9000 c822030cc576 sh /app/test/play/docker-entrypoint.sh /app/test/play/servers/server01/play/conf/override.conf /app/log/nflott/play true dev

我的参数:

$2:/app/test/play/servers/server01/play/conf/override.conf
$3:/app/log/nflott/play
$4:true
$5:dev Which needs to be passed to the docker-entrypoint.sh Script

我的entrypoint.sh脚本代码:

        echo "CONFIG:$2
        echo "LOG_HOME:$3"
        echo "SKIP_LOGFILE:$4"
        echo "LOG_ENV:$5

        /app/test/play/servers/server01/play/bin/apiserver  \
         -Dconfig.file=/app/test/play/servers/server01/play/conf/override.conf \
         -Dpidfile.path=/app/test/play/servers/server01/RUNNING_PID \
         -DLOG_HOME=$3 \
         -DSKIP_LOGFILE=$4 \
         -DLOG_ENV=$5 \

     Error:
        CONFIG:/app/test/play/servers/server01/play/conf/override.conf
        LOG_HOME:/app/log/nflott/play
        SKIP_LOGFILE:true
        LOG_ENV:dev
        Bad root server path: /app/nflott/play/docker-entrypoint.sh

在echo语句之后似乎我的参数没有传递给逻辑块,并且它的Bad Root服务器路径问题失败了。如何解决Bad root serer路径错误并运行我的脚本?

2 个答案:

答案 0 :(得分:0)

恕我直言,他们可能会被作为docker命令的args传递。您可以尝试使用-e docker选项将它们作为一些命名的env变量传递给docker容器,然后在脚本中进行访问。

答案 1 :(得分:0)

您可以使用特殊--entrypoint标记并在cmd中传递参数:

sudo docker run -it -p 80:9000 --entrypoint /app/test/play/docker-entrypoint.sh c822030cc576 /app/test/play/servers/server01/play/conf/override.conf /app/log/nflott/play true dev