我有一个ECS配置,我正在启动。然而,nginx frontend容器失败的原因是:
nginx: [emerg] host not found in upstream “backend”这在本地可以很好地工作,但似乎ECS无法解析码头容器名称。
我正在使用ecs-cli进行部署。发射类型为EC2。网络模式为bridge。
命令:
ecs-cli compose \
--cluster mycluster \
--file docker-compose.yml \
--ecs-params ecs-params.yml service up \
--deployment-min-healthy-percent=50 --force-deployment \
--target-groups targetGroupArn=<load-balancer>,containerName=frontend,containerPort=80 \
--health-check-grace-period 60 \
--role <my-role> \
--timeout 30ecs-params.yml
task_definition:
task_role_arn: <my-arn>
task_execution_role: <my-exec-role>
services:
backend:
essential: true
mem_reservation: 1024m
frontend:
essential: true
mem_reservation: 1024mnginx.conf
events {
worker_connections 1024;
}
http {
server_tokens off;
upstream backend_server {
server backend:8001;
}
server {
listen 80;
listen [::]:80;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
location /api {
proxy_pass http://backend_server/api;
}
}
}docker-compose
version: '3'
services:
backend:
image: <backend-image>
ports:
- 8001:8001
frontend:
image: <frontend-image, built locally with the nginx conf>
ports:
- 80:80任务定义:
{
"ipcMode": null,
"executionRoleArn": <exec-role>,
"containerDefinitions": [
{
"dnsSearchDomains": [],
"environmentFiles": null,
"logConfiguration": {
"logDriver": "awslogs",
"secretOptions": null,
"options": { <log-options>
}
},
"entryPoint": [],
"portMappings": [
{
"hostPort": 8001,
"protocol": "tcp",
"containerPort": 8001
}
],
"command": [],
"linuxParameters": {
"capabilities": {
"add": null,
"drop": null
},
"sharedMemorySize": null,
"tmpfs": null,
"devices": [],
"maxSwap": null,
"swappiness": null,
"initProcessEnabled": null
},
"cpu": 0,
"environment": [
],
"resourceRequirements": null,
"ulimits": null,
"dnsServers": [],
"mountPoints": [],
"workingDirectory": null,
"secrets": null,
"dockerSecurityOptions": [],
"memory": null,
"memoryReservation": 1024,
"volumesFrom": [],
"stopTimeout": null,
"image": <backend-image>,
"startTimeout": null,
"firelensConfiguration": null,
"dependsOn": null,
"disableNetworking": null,
"interactive": null,
"healthCheck": null,
"essential": true,
"links": [],
"hostname": null,
"extraHosts": [],
"pseudoTerminal": false,
"user": null,
"readonlyRootFilesystem": false,
"dockerLabels": null,
"systemControls": null,
"privileged": false,
"name": "backend"
},
{
"dnsSearchDomains": [],
"environmentFiles": null,
"logConfiguration": {
"logDriver": "awslogs",
"secretOptions": null,
"options": { <log-options>
}
},
"entryPoint": [],
"portMappings": [
{
"hostPort": 80,
"protocol": "tcp",
"containerPort": 80
}
],
"command": [],
"linuxParameters": {
"capabilities": {
"add": null,
"drop": null
},
"sharedMemorySize": null,
"tmpfs": null,
"devices": [],
"maxSwap": null,
"swappiness": null,
"initProcessEnabled": null
},
"cpu": 0,
"environment": [],
"resourceRequirements": null,
"ulimits": null,
"dnsServers": [],
"mountPoints": [],
"workingDirectory": null,
"secrets": null,
"dockerSecurityOptions": [],
"memory": null,
"memoryReservation": 1024,
"volumesFrom": [],
"stopTimeout": null,
"image": <frontend-image>,
"startTimeout": null,
"firelensConfiguration": null,
"dependsOn": null,
"disableNetworking": null,
"interactive": null,
"healthCheck": null,
"essential": true,
"links": [],
"hostname": null,
"extraHosts": [],
"pseudoTerminal": false,
"user": null,
"readonlyRootFilesystem": false,
"dockerLabels": null,
"systemControls": null,
"privileged": false,
"name": "frontend"
}
],
"placementConstraints": [],
"memory": null,
"taskRoleArn": <task-role-arn>,
"compatibilities": [
"EXTERNAL",
"EC2"
],
"taskDefinitionArn": <definition>,
"family": "<my-family>",
"requiresAttributes": [
{
"targetId": null,
"targetType": null,
"value": null,
"name": "com.amazonaws.ecs.capability.logging-driver.awslogs"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "ecs.capability.execution-role-awslogs"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "com.amazonaws.ecs.capability.ecr-auth"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.19"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.17"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.21"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "com.amazonaws.ecs.capability.task-iam-role"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "ecs.capability.execution-role-ecr-pull"
}
],
"pidMode": null,
"requiresCompatibilities": [],
"networkMode": null,
"runtimePlatform": null,
"cpu": null,
"revision": 75,
"status": "ACTIVE",
"inferenceAccelerators": null,
"proxyConfiguration": null,
"volumes": []
}发布于 2022-08-25 10:56:27
@MarkB是正确的。我需要添加链接。这样做的方法是通过docker-compose.yml
version: '3'
services:
backend:
image: <backend-image>
ports:
- 8001:8001
frontend:
image: <frontend-image, built locally with the nginx conf>
links: ["backend"]
ports:
- 80:80我还向ecs-params.yml添加了一个健康检查,以确保后端在前端之前启动。
之所以发生这种情况,是因为ECS网桥是默认网桥。它不允许根据容器的名称(因此链接)解析容器。我以为那是一座用户定义的桥梁。更多信息可以在码头工人文件上找到。
https://stackoverflow.com/questions/73460644
复制相似问题