如何将参数传递给在CLI(命令行界面)中运行的docker? [英] How do I pass arguments to docker run in a CLI (Command Line Interface)?
问题描述
我需要我的图片以以下命令开头:
I need my image to start with this command:
docker run -it --rm --security-opt seccomp=./chrome.json <image_id>
我正在将其部署到Google Compute Engine: https://cloud.google.com/compute/docs/containers/deploying-containers
I'm deploying it to Google Compute Engine: https://cloud.google.com/compute/docs/containers/deploying-containers
据我了解,我无法在此处指定参数,因此Google Cloud仅使用 docker run
命令启动它.
As far as I understand, I can't specify arguments there, so Google Cloud starts it with just docker run
command.
如何传递这些参数?也许我可以以某种方式在Dockerfile中指定这些args?
How do I pass these arguments? Maybe I can specify those args in Dockerfile somehow?
推荐答案
当您使用该功能直接在Compute Engine上部署容器时,仅限于
When you use the feature to deploy container directly on Compute Engine, you are limited to the definition of
- 入口点
- Args在入口点通过
- 环境变量
仅此而已,您无法添加其他/自定义参数.
That's all, you can't add additional/custom params.
One solution is, instead of using the built in feature, to use the container-optimized OS (COS) on your Compute Engine and to create a startup script to download and run the container with the docker args that you want
METADATA=http://metadata.google.internal/computeMetadata/v1
SVC_ACCT=$METADATA/instance/service-accounts/default
ACCESS_TOKEN=$(curl -H 'Metadata-Flavor: Google' $SVC_ACCT/token | cut -d'"' -f 4)
docker login -u oauth2accesstoken -p $ACCESS_TOKEN https://gcr.io
docker run … gcr.io/your-project/your-image
在最后一行,您可以在启动脚本中自定义运行参数.
On the latest line, you can customize the run param in your startup script.
因此,现在,对于更新,您必须更新启动脚本并重置VM(或使用COS和新的启动脚本创建新的Compute Engine;并删除前一个).
So now, for the update, you have to update the startup script and to reset your VM (or to create a new Compute Engine with COS and the new startup script; and to delete the previous one).
内置功能的便利性与自定义功能之间需要权衡取舍.
It's matter of tradeoff between the convenience of a built in feature and the customization capacity.
这篇关于如何将参数传递给在CLI(命令行界面)中运行的docker?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!