如何使用命令将参数传递给带有Python脚本脚本的docker容器? [英] How can I pass arguments to a docker container with a python entry-point script using command?

查看:1368
本文介绍了如何使用命令将参数传递给带有Python脚本脚本的docker容器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个docker的图像与python脚本作为入口点,我想传递参数到python脚本,当容器运行。我试图使用sys.argv和sys.stdin获取参数,但是两者都没有工作。我试图运行容器:

  docker运行图像参数
/ pre>

解决方案

这取决于entrypoint的设置。如果它以exec形式设置,那么您只需在 docker运行命令之后传递参数,如下所示:

  docker run image -a -b -c 

如果它是以shell形式设置的,那么你不得不覆盖entrypoint,不幸的是,

  $ docker run --entrypoint echo image hi 
hi

您可以使用 docker检查表单检查。如果入口点似乎以 / bin / sh -c 开始,那么它是shell窗体。



参考:




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:

docker run image argument

解决方案

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 run command, like this:

docker run image -a -b -c

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

$ 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.

References:

这篇关于如何使用命令将参数传递给带有Python脚本脚本的docker容器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆