简体   繁体   English

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

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

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. 所以我有一个带有python脚本的docker镜像作为入口点,我想在运行容器时将参数传递给python脚本。 I've tried to get the arguments using sys.argv and sys.stdin, but neither has worked. 我试图使用sys.argv和sys.stdin来获取参数,但两者都没有用。 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: 如果它是以“exec form”设置的,那么你只需在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 . 您可以使用docker inspect表单。 If the entrypoint appears to begin with /bin/sh -c , then it is shell form. 如果入口点似乎以/bin/sh -c开头,则它是shell形式。

References: 参考文献:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 AWS Elasticbeanstalk 中执行 python 入口点命令时如何包含命令? - How to include command when executing python entry-point command in AWS Elasticbeanstalk? Python Tkinter 入口点 - Python Tkinter entry-point 如何将参数传递给在 docker 容器内运行的 python 脚本? - How to pass arguments to the python script that is running inside docker container? 如何使用python脚本将参数传递给linux命令提示符 - How to pass arguments to linux command prompt using python script 如何使用shell命令将目录作为参数传递给python脚本? - how to pass directory as arguments to python script using shell command? 使用 argparser 将 arguments 传递到入口点 python 脚本 - Passing arguments to an entry point python script using argparser 通过带有参数的入口点函数启动Docker容器 - Start docker container through an entry point function with arguments 如何将 arguments 传递给我 Tkinter 中的 python 脚本 - How can I pass arguments to my python script in Tkinter 在 Docker 容器中将参数传递给 Python argparse - Pass arguments to Python argparse within Docker container 在 Docker 容器内传递 python arguments (argparse) - Pass python arguments (argparse) within Docker container
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM