docker在AWS ECS中运行程序参数 [英] docker run program arguments in aws ecs
问题描述
我在Amazon的ECS中有一个工作容器,该容器将程序作为任务运行.我想传递一些程序参数,就像使用docker run
在本地运行时所做的那样.我设法在ECS的容器配置中传递了一个新的入口点,就像在docker run
命令行中传递它一样.
I have a working container in Amazon's ECS that runs a program as a task. I would like to pass some program arguments, as I would do when running locally with docker run
. I have managed to do passing a new entrypoint in the container configuration in ECS, as if I were passing it in the docker run
command line.
不幸的是,这样做时,我将覆盖映像中已经定义的内部入口点.我想使用内部入口点,只是添加一些其他命令行参数,例如--debug
选项.有什么办法吗?
Unfortunately, when doing so, I am overriding the internal entrypoint that was already defined in the image. I would like to use the internal entrypoint, just adding some more command line arguments, like --debug
options. Is there any way to do that?
谢谢.
推荐答案
1..如果您通常将命令行参数传递给
1. If you normally pass in command line arguments to your script like
python myscript.py --debug --name "joe schmoe" --quality best --dimensions 1920 1080
2..您有一个带有入口点的docker映像,用于运行该脚本,例如
2. And you have a docker image with an entrypoint to run that script like
FROM python:3.7-alpine
# Add the application folder to the container
COPY . /myscript
WORKDIR /myscript
# Install required packages
RUN pip install -r requirements.txt --upgrade
# Run the script when the container is invoked
ENTRYPOINT ["python", "myscript.py"]
3.然后,当通过aws ecs用户界面编辑任务/容器定义时,必须将参数放在容器设置的环境"部分下的命令"字段中,并用逗号替换参数和值之间的所有空格,例如:
3. Then when editing a task/container definition via the aws ecs user interface, you must place the arguments into the "Command" field under the "Environment" section of the container settings and replace all spaces between arguments and values with commas, like so:
--debug,--name,joe schmoe,--quality,best,--dimensions,1920,1080
空格为joe schmoe
的项目被引用为"joe schmoe",这就是为什么--quality best
之类的项不起作用的原因,而需要用逗号分隔为--quality,best
Items with spaces like joe schmoe
are quoted as "joe schmoe", which is why something like --quality best
wouldn't work, and instead needs to be comma delimited as --quality,best
4..创建任务后,如果您查看任务定义中的容器详细信息,该命令将显示为:
4. After creating the task, if you take a look at the container details in the task definition, the command is displayed as:
["--debug","--name","joe schmoe","--quality","best","--dimensions","1920","1080"]
,与Dockerfile中的 CMD 指令接受的语法相同
which is the same syntax accepted by the CMD instruction in a Dockerfile.
这篇关于docker在AWS ECS中运行程序参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!