我努力让我的node.js容器在ECS上运行。当我使用docker compose在本地运行它时运行正常,但在ECS上它运行2-3分钟并处理几个连接(来自负载均衡器的2-3次运行状况检查),然后关闭。我无法解决原因。
我的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"
}
...
}
在我的docker-compose.yml中,我使用nodemon -
运行node:
...
command: nodemon
在我的cloudWatch日志中,我可以看到一切开始 -
14:20:24 npm info lifecycle my_app@1.0.0~start: my_app@1.0.0
然后我看到健康状况检查请求(全部使用http 200' s),稍后它会全部结束 -
14:23:00 npm info lifecycle mapov_reporting@1.0.0~poststart: mapov_reporting@1.0.0
14:23:00 npm info ok
我已尝试在forever-monitor中包装我的start.js脚本,但这似乎没有任何区别。
更新
我的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之外,没有任何记录。
答案 0 :(得分:1)
我使用的是旧版本的mongo驱动程序~2.0
,并保持与多个数据库的连接。当我升级驱动程序时,问题就消失了。
"dependencies": {
"mongodb": ">=2.2"
}
我只能假设驱动程序中存在错误。