使用 Docker Compose 从 EC2 运行 Flask 创建 AMI 映像后出现 502 Bad Gateway
502 Bad Gateway after AMI Image creation from EC2 running Flask using Docker Compose
我的应用程序还提供 NPM React 应用程序以及附加了 RDS 的 Flask 后端。它是 运行 双栈。
我能够追踪到我的网站进入了 502 错误网关。在我创建 AMI 映像以将 Ec2 实例复制到我的其他帐户后一分钟。现在我部署了实例并尝试了运行(还没有运行)。
AMI 创建的 Cloud Trail 日志
{
"eventVersion": "1.05",
"userIdentity": {
"type": "IAMUser",
"principalId": "",
"arn": "",
"accountId": "",
"accessKeyId": "",
"userName": "",
"sessionContext": {
"sessionIssuer": {},
"webIdFederationData": {},
"attributes": {
"mfaAuthenticated": "false",
"creationDate": "2019-09-13T02:30:45Z"
}
}
},
"eventTime": "2019-09-13T04:30:01Z",
"eventSource": "ec2.amazonaws.com",
"eventName": "CreateImage",
"awsRegion": "ap-southeast-2",
"sourceIPAddress": "***.66.79.65",
"userAgent": "console.ec2.amazonaws.com",
"requestParameters": {
"instanceId": "****05818a11a690e",
"name": "devport",
"description": "Port to Developer version of new one",
"noReboot": false,
"blockDeviceMapping": {
"items": [
{
"deviceName": "/dev/xvda",
"ebs": {
"volumeSize": 20,
"deleteOnTermination": true,
"volumeType": "gp2",
"encrypted": false
}
}
]
}
},
"responseElements": {
"requestId": "******-3cfb-49d0-917f-78641a0561cc",
"imageId": "ami-*****bfa644e5a043"
},
"requestID": "*****-3cfb-49d0-917f-78641a0561cc",
"eventID": "******-7780-4d61-900b-607378d7dc88",
"eventType": "AwsApiCall",
"recipientAccountId": ""
}
从实例创建 AMI 时,它有两个选项,要么在创建 AMI 期间重新启动,要么立即执行,但不推荐使用第二个。
因此,如果您没有检查 502 错误网关,那么在您重新启动容器之前,如果它没有自动重启,则预计会出现错误。
您只能在其就绪状态下share AMI。
因此在第 4 步它重新启动实例并在第 5 步之后准备共享。
noReboot(布尔值)
By default this property is set to false, which means Amazon EC2
attempts to cleanly shut down the instance before image creation and
reboots the instance afterwards. When set to true, Amazon EC2 does not
shut down the instance before creating the image. When this option is
used, file system integrity on the created image cannot be guaranteed.
Default is FALSE.
我的应用程序还提供 NPM React 应用程序以及附加了 RDS 的 Flask 后端。它是 运行 双栈。 我能够追踪到我的网站进入了 502 错误网关。在我创建 AMI 映像以将 Ec2 实例复制到我的其他帐户后一分钟。现在我部署了实例并尝试了运行(还没有运行)。
AMI 创建的 Cloud Trail 日志
{
"eventVersion": "1.05",
"userIdentity": {
"type": "IAMUser",
"principalId": "",
"arn": "",
"accountId": "",
"accessKeyId": "",
"userName": "",
"sessionContext": {
"sessionIssuer": {},
"webIdFederationData": {},
"attributes": {
"mfaAuthenticated": "false",
"creationDate": "2019-09-13T02:30:45Z"
}
}
},
"eventTime": "2019-09-13T04:30:01Z",
"eventSource": "ec2.amazonaws.com",
"eventName": "CreateImage",
"awsRegion": "ap-southeast-2",
"sourceIPAddress": "***.66.79.65",
"userAgent": "console.ec2.amazonaws.com",
"requestParameters": {
"instanceId": "****05818a11a690e",
"name": "devport",
"description": "Port to Developer version of new one",
"noReboot": false,
"blockDeviceMapping": {
"items": [
{
"deviceName": "/dev/xvda",
"ebs": {
"volumeSize": 20,
"deleteOnTermination": true,
"volumeType": "gp2",
"encrypted": false
}
}
]
}
},
"responseElements": {
"requestId": "******-3cfb-49d0-917f-78641a0561cc",
"imageId": "ami-*****bfa644e5a043"
},
"requestID": "*****-3cfb-49d0-917f-78641a0561cc",
"eventID": "******-7780-4d61-900b-607378d7dc88",
"eventType": "AwsApiCall",
"recipientAccountId": ""
}
从实例创建 AMI 时,它有两个选项,要么在创建 AMI 期间重新启动,要么立即执行,但不推荐使用第二个。
因此,如果您没有检查 502 错误网关,那么在您重新启动容器之前,如果它没有自动重启,则预计会出现错误。
您只能在其就绪状态下share AMI。
noReboot(布尔值)
By default this property is set to false, which means Amazon EC2 attempts to cleanly shut down the instance before image creation and reboots the instance afterwards. When set to true, Amazon EC2 does not shut down the instance before creating the image. When this option is used, file system integrity on the created image cannot be guaranteed. Default is FALSE.