所以我在同一个EC2示例上有3个容器- Nodejs,DB和Flask。Nodejs与DB容器连接良好,所有路由都正常工作。有一个从Nodejs到flask的路由给出了“内部服务器错误”。我在任务定义中使用“host”networkMode,容器之间的连接可以使用'localhost:xxxx'实现。
post请求发送一个图像文件,并返回一个json作为响应。
相同的路由工作正常,并给出正确的结果,当我从我的本地测试:即,本地路由上的Node容器到AWS EC2上的Flask容器。
我不明白EC2端的问题是什么,但在本地工作正常。所有的入站规则都是正确的。节点在端口3000, flask 在端口5000
连接到flask API的节点上的代码:
form.append('image', fs.createReadStream(path.join(path.resolve(''),'/assets/images', image.filename)));
/**Redirect to flask API with image fileand delete from local*/
const urlProxy = new Proxy(redirectMapping, validator);
const response = await fetch(urlProxy.predict, { method: 'POST', body: form });
const flaskData = await response.json();
await unlink(path.join(path.resolve(''),'/assets/images', image.filename))
下面是task-definition.yaml中的容器定义:
"containerDefinitions": [
{
"name": "KlemFlask",
"image": "klemrepo:latest",
"cpu": 0,
"memoryReservation": 128,
"portMappings": [
{
"containerPort": 5000,
"hostPort": 5000,
"protocol": "tcp"
}
],
"essential": true,
"environment": [],
"mountPoints": [],
"volumesFrom": []
}
},
{
"name": "klemweb",
"image": "klemtech/node-prod",
"cpu": 0,
"memoryReservation": 50,
"portMappings": [
{
"containerPort": 3000,
"hostPort": 3000,
"protocol": "tcp"
}
],
"essential": true,
"environment": [],
"environmentFiles": [
{
"value": "klempgdata/node.env",
"type": "s3"
}
],
"mountPoints": [],
"volumesFrom": [],
"dependsOn": [
{
"containerName": "klemdb",
"condition": "START"
}
]
},
{
"name": "klemdb",
"image": "postgres:14-alpine",
"cpu": 0,
"memoryReservation": 50,
"portMappings": [
{
"containerPort": 5432,
"hostPort": 5432,
"protocol": "tcp"
}
],
"essential": true,
"environment": [],
"environmentFiles": [
{
"value": "klempgdata/database.env",
"type": "s3"
}
],
"mountPoints": [
{
"sourceVolume": "pgdata",
"containerPath": "/var/lib/postgresql/data"
}
],
"volumesFrom": []
}
1条答案
按热度按时间zphenhs41#
谢谢大家,真实的的问题是节点容器中工作目录的权限。更改权限解决了这个问题