您可以将标志传递给docker运行的命令吗? [英] Can you pass flags to the command that docker runs?
问题描述
run
命令的文档遵循以下语法:
The documentation for the run
command follows the following syntax:
docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]
但是我有时发现我想将标志传递给 [COMMAND]
。
however I've found at times that I want to pass a flag to [COMMAND]
.
例如,我一直在使用此图片,其中 [COMMAND ]
(在 Dockerfile 中指定)是:
For example, I've been working with this image, where the [COMMAND]
as specified in the Dockerfile is:
CMD ["/bin/bash", "-c", "/opt/solr/bin/solr -f"]
有没有办法将标志附加到 / opt / solr / bin / solr -f
使其格式为 / opt / solr / bin / solr -f [-MY FLAGS]
?
Is there any way to tack on flags to "/opt/solr/bin/solr -f"
so that it's in the form "/opt/solr/bin/solr -f [-MY FLAGS]"
?
我需要编辑DockerFile还是为此内置一些功能?
Do I need to edit the DockerFile or is there some built in functionality for this?
推荐答案
CMD
指令如果在 docker run
命令中未指定任何命令,则Dockerfile 是容器启动时将运行的命令。
The CMD
directive of a Dockerfile is the command that would be run when the container starts if no command was specified in the docker run
command.
CMD的主要目的是为执行中的容器提供默认值。
The main purpose of a CMD is to provide defaults for an executing container.
在您的情况下,只需按以下方式使用 docker run
命令覆盖在中指定的默认命令 Dockerfile :
In your case, just use the docker run
command as follow to override the default command specified in the Dockerfile:
docker run makuk66/docker-solr /bin/bash -c "/opt/solr/bin/solr -f [your flags]"
这篇关于您可以将标志传递给docker运行的命令吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!