2017-06-20 87 views
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以外,沒有任何記錄。

+0

您是否嘗試過使用與您的ECS任務配置完全相同的命令在本地運行它? –

+0

謝謝@PaulBecotte - 是的,我現在就試過 - 它已經跑了5分鐘,沒有問題。 –

+0

你能分享你的ECS任務定義嗎? –

回答

0

我使用的是mongo驅動程序的舊版本~2.0,並保持與多個數據庫的連接。當我升級司機時,問題就消失了。

"dependencies": { 
    "mongodb": ">=2.2" 
    } 

我只能假設驅動程序中有一個錯誤。

相關問題