我正在尝试在AWS Beanstalk上部署多个node.js微服务,并希望它们部署在同一实例上。这是我第一次部署多个服务,所以我需要有人帮助我解决一些故障。因此,我首先尝试将它们打包到一个Docker容器中。同时我使用Docker Compose来管理结构。它在我的虚拟机上本地运行良好,但当我将其部署到Beanstalk时,遇到了一些问题。
我知道的:
- 我知道我必须选择部署为多容器Docker。
- 管理多个node.js服务的最佳方法是使用Docker Compose。
- 我需要一个
dockerrun.aws.json
文件来运行node.js应用程序。 - 我需要为该ECS实例创建任务定义。
我遇到的问题:
- 我只能找到php的
dockerrun.aws.json
和task_definition.json
模板,因此我无法验证那两个JSON文件中的node.js配置是否正确。 - 看起来
docker-compose.yml
、dockerrun.aws.json
和task_definition.json
都在进行相似的工作。我必须保留task_definition
,但我是否还需要dockerrun.aws.json
? - 我尝试在ECS中运行任务,但它立即停止。我如何检查任务的日志记录?
我得到了:
在环境中找不到ECS任务定义(或空定义文件)
因为我的任务总是会立即停止。如果我能够检查日志,那么进行故障排除将更加容易。
这是我的task_definition.json
:
{
"requiresAttributes": [],
"taskDefinitionArn": "arn:aws:ecs:us-east-1:231440562752:task-definition/ComposerExample:1",
"status": "ACTIVE",
"revision": 1,
"containerDefinitions": [
{
"volumesFrom": [],
"memory": 100,
"extraHosts": null,
"dnsServers": null,
"disableNetworking": null,
"dnsSearchDomains": null,
"portMappings": [
{
"hostPort": 80,
"containerPort": 80,
"protocol": "tcp"
}
],
"hostname": null,
"essential": true,
"entryPoint": null,
"mountPoints": [
{
"containerPath": "/usr/share/nginx/html",
"sourceVolume": "webdata",
"readOnly": true
}
],
"name": "nginxexpressredisnodemon_nginx_1",
"ulimits": null,
"dockerSecurityOptions": null,
"environment": [],
"links": null,
"workingDirectory": null,
"readonlyRootFilesystem": null,
"image": "nginxexpressredisnodemon_nginx",
"command": null,
"user": null,
"dockerLabels": null,
"logConfiguration": null,
"cpu": 99,
"privileged": null
}
],
"volumes": [
{
"host": {
"sourcePath": "/ecs/webdata"
},
"name": "webdata"
}
],
"family": "ComposerExample"
}