如何使用命令将参数传递给带有 python 入口点脚本的 docker 容器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31523551/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 10:09:46  来源:igfitidea点击:

How can I pass arguments to a docker container with a python entry-point script using command?

pythondocker

提问by dporter

So I've got a docker image with a python script as the entry-point and I would like to pass arguments to the python script when the container is run. I've tried to get the arguments using sys.argv and sys.stdin, but neither has worked. I'm trying to run the container using:

所以我有一个以 python 脚本为入口点的 docker 镜像,我想在容器运行时将参数传递给 python 脚本。我尝试使用 sys.argv 和 sys.stdin 获取参数,但都没有奏效。我正在尝试使用以下方法运行容器:

docker run image argument

采纳答案by kojiro

It depends how the entrypoint was set up. If it was set up in "exec form" then you simply pass the arguments after the docker runcommand, like this:

这取决于入口点是如何设置的。如果它是以“exec 形式”设置的,那么您只需在docker run命令后传递参数,如下所示:

docker run image -a -b -c

If it was set up in "shell form" then you have to override the entrypoint, unfortunately.

不幸的是,如果它是以“shell 形式”设置的,那么您必须覆盖入口点。

$ docker run --entrypoint echo image hi
hi

You can check the form using docker inspect. If the entrypoint appears to begin with /bin/sh -c, then it is shell form.

您可以使用 来检查表单docker inspect。如果入口点似乎以 开头/bin/sh -c,则它是 shell 形式。

References:

参考: