如何仅使用CMD命令传递选项? [英] How to pass only options with the CMD command?
问题描述
假设我的控件之外有一个图像指定了自定义入口点.我们称之为 server
Suppose there's an image outside of my control that specifies custom entry point. Let's call it server
# server's Dockerfile
ENTRYPOINT /usr/bin/server
我正在基于服务器构建映像.我想指定要执行的默认命令.它应该调用服务器的入口点并向其传递参数.该参数是一个选项.一个幼稚的解决方案看起来像这样:
I'm building an image based on the server. I'd like to specify a default command to be executed. It should call the server's entrypoint and pass an argument to it. The argument is a single option. A naive solution would look like this:
FROM server:latest
CMD --port 8080
但是,这在 docker build
与
Error response from daemon: Dockerfile parse error line 3: Unknown flag: port
如何使用CMD将参数传递给以-
开头的入口点?
How can I use CMD to pass arguments to entry point that start with --
?
推荐答案
命令定义如下:
CMD [ "--port", "8080" ]
否则,将-port
作为标志附加到CMD命令本身,而不是它实际运行的命令.
Where otherwise the --port
gets attached to the CMD command itself as a flag, not the actual command it runs.
这假定 ENTRYPOINT
只能正确处理选项,并且不需要像传统情况那样需要可执行文件的路径.
This presumes that the ENTRYPOINT
can properly handle just options and doesn't require a path of an executable as is traditionally the case.
这篇关于如何仅使用CMD命令传递选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!