0
我正努力让我的node.js容器在ECS上运行。当我使用docker撰写本地文件时,它运行良好,但在ECS上运行2-3分钟并处理几个连接(负载均衡器进行2-3次健康检查),然后关闭。我无法弄清楚为什么。如何在不退出的情况下在AWS ECS上运行节点容器
我Dockerfile -
FROM node:6.10
RUN npm install -g nodemon \
&& npm install forever-monitor \
winston \
express-winston
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json /usr/src/app/
RUN npm install
COPY . /usr/src/app
EXPOSE 3000
CMD [ "npm", "start" ]
然后在我的package.json -
{
...
"main": "forever.js",
"dependencies": {
"mongodb": "~2.0",
"abbajs": ">=0.1.4",
"express": ">=4.15.2"
}
...
}
在我的码头工人,compose.yml我nodemon运行 -
node:
...
command: nodemon
在我的CloudWatch日志我可以看到一切都开始 -
14:20:24 npm info lifecycle [email protected]~start: [email protected]
然后我看到了健康检查的要求(所有HTTP 200的),那么稍后这一切包扎 -
14:23:00 npm info lifecycle [email protected]~poststart: [email protected]
14:23:00 npm info ok
我已经试过包装我start.js脚本forever-monitor,但似乎没有任何区别。
UPDATE
我ECS任务定义 -
{
"requiresAttributes": [
{
"value": null,
"name": "com.amazonaws.ecs.capability.ecr-auth",
"targetId": null,
"targetType": null
},
{
"value": null,
"name": "com.amazonaws.ecs.capability.logging-driver.awslogs",
"targetId": null,
"targetType": null
},
{
"value": null,
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.19",
"targetId": null,
"targetType": null
}
],
"taskDefinitionArn": "arn:aws:ecs:us-east-1:562155596068:task-definition/node:12",
"networkMode": "bridge",
"status": "ACTIVE",
"revision": 12,
"taskRoleArn": null,
"containerDefinitions": [
{
"volumesFrom": [],
"memory": 128,
"extraHosts": null,
"dnsServers": null,
"disableNetworking": null,
"dnsSearchDomains": null,
"portMappings": [
{
"hostPort": 0,
"containerPort": 3000,
"protocol": "tcp"
}
],
"hostname": null,
"essential": true,
"entryPoint": null,
"mountPoints": [],
"name": "node",
"ulimits": null,
"dockerSecurityOptions": null,
"environment": [
{
"name": "awslogs-group",
"value": "node_logs"
},
{
"name": "awslogs-region",
"value": "us-east-1"
},
{
"name": "NODE_ENV",
"value": "production"
}
],
"links": null,
"workingDirectory": null,
"readonlyRootFilesystem": null,
"image": "562155596068.dkr.ecr.us-east-1.amazonaws.com/node:06b5a3700df163c8563865c2f23947c2685edd7b",
"command": null,
"user": null,
"dockerLabels": null,
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "node_logs",
"awslogs-region": "us-east-1"
}
},
"cpu": 1,
"privileged": null,
"memoryReservation": null
}
],
"placementConstraints": [],
"volumes": [],
"family": "node"
}
任务都停止与状态Task failed ELB health checks in (target-group ...
。在他们开始失败之前,健康检查通过2或3次。除了日志中的http 200以外,没有任何记录。
您是否尝试过使用与您的ECS任务配置完全相同的命令在本地运行它? –
谢谢@PaulBecotte - 是的,我现在就试过 - 它已经跑了5分钟,没有问题。 –
你能分享你的ECS任务定义吗? –