英文:
Getting blank output while CMD & ENTRYPOINT instructions together
问题
以下是您要翻译的内容:
我的 dockerfile
如下所示:
FROM ubuntu
ENTRYPOINT echo
CMD ["helloworld"]
从上述 Dockerfile 构建的容器映像产生了空白输出。
[root@dockerhost dproj]# docker run -it --name con1 demo
[root@dockerhost dproj]#
期望的输出:
helloworld
英文:
My dockerfile
looks as below:
FROM ubuntu
ENTRYPOINT echo
CMD ["helloworld"]
The container built from the above dockerfile image is giving a blank output.
[root@dockerhost dproj]# docker run -it --name con1 demo
[root@dockerhost dproj]#
Expected Output:
helloworld
答案1
得分: 2
从https://docs.docker.com/engine/reference/builder/#entrypoint:
壳形式:
ENTRYPOINT 命令 参数1 参数2壳形式阻止使用任何CMD或运行命令行参数,但它的缺点是您的ENTRYPOINT将作为/bin/sh -c的子命令启动
从man sh
:
-c 从command_string操作数中读取命令。将特殊参数0(参见第2.5.2节,特殊参数)的值设置为command_name操作数的值,并依次从剩余的参数操作数中设置位置参数($1、$2等)。不会从标准输入读取任何命令。
/bin/sh -c echo helloworld
应该将helloworld
分配给_shell_的$0
并执行echo
,它将输出一个空行。
也就是说,ENTRYPOINT ["echo"]
不等同于ENTRYPOINT echo
。
英文:
From https://docs.docker.com/engine/reference/builder/#entrypoint :
> The shell form:
> ENTRYPOINT command param1 param2
>
>
> The shell form prevents any CMD or run command line arguments from being used, but has the disadvantage that your ENTRYPOINT will be started as a subcommand of /bin/sh -c
From man sh
:
-c Read commands from the command_string operand. Set the value of special parameter 0 (see Section 2.5.2, Special Parameters) from the
value of the command_name operand and the positional parameters ($1, $2, and so on) in sequence from the remaining argument operands.
No commands shall be read from the standard input.
/bin/sh -c echo helloworld
should assign helloworld
to shells $0
and execute echo
, which will output an empty line.
I.e. ENTRYPOINT ["echo"]
is not ENTRYPOINT echo
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论