即使CMD应该等待,AWS ECS也会继续产生新的任务

就好像CMD没有效果一样。

在我的ECS任务定义中,我已经定义了如下面截图所示的命令

在这里输入图像说明

python进程应该是一个“阻塞进程” – 它假定等待SQS队列中的数据。

但是,从云计算日志看来,似乎这个任务不断产生 在这里输入图像说明

实际上它就像执行这个

docker run -t simplequeue python /docverter/app/src/main.py 

容器启动,然后立即终止。

我在我的dockerfile中定义了ENTRYPOINT

 FROM ubuntu:16.04 RUN apt-get update -y --fix-missing RUN apt-get install -y git python python-pip cron ntp ENV APP_HOME /docverter RUN mkdir -p ${APP_HOME} COPY . ${APP_HOME} # # Log configuration RUN mkdir -p /root/.aws RUN mkdir -p /var/awslogs/state COPY ./credentials /root/.aws/credentials COPY docker-entrypoint.sh /docker-entrypoint.sh RUN apt-get install -y curl RUN curl https://s3.amazonaws.com/aws-cloudwatch/downloads/latest/awslogs-agent-setup.py -O RUN python awslogs-agent-setup.py --non-interactive -c ${APP_HOME}/aws-log.cfg --region ap-southeast-2 # Entry point # To ensure some background services are started when the container is started ENTRYPOINT /docker-entrypoint.sh 

docker入口点如下:

 #!/bin/bash set -eo pipefail service awslogs start service ntp start 

我想知道如何让Docker容器在任务定义中执行Command

编辑根据Andrey的答案,我已经修改了入口点脚本,但它不能解决问题。 我添加了一个额外的echo "$@"进行debugging,它打印空白。

 docker build -t broken . docker run -it broken python # export to have python started 

testing代码可以从这里克隆: git clone -b broken-entry-point-and-cmd https://github.com/kongakong/aws-ecs

您需要在ENTRYPOINT脚本的末尾添加以下内容

 exec "$@" 

因为您正在使用ENTRYPOINT和CMD,CMD值作为parameter passing给ENTRYPOINT。

所以你需要告诉你的bash脚本启动python命令。

http://stackoverflow.com/questions/32255814/what-purpose-does-using-exec-in-docker-entrypoint-scripts-serve?rq=1

https://www.ctl.io/developers/blog/post/dockerfile-entrypoint-vs-cmd/