【发布时间】:2022-02-08 10:24:16
【问题描述】:
我在 terraform 中遇到错误:
ClientException: Links are not supported when networkMode=awsvpc.
我将 nginx 与我的 nodejs 应用程序链接起来。我希望 nodejs 在 3000 端口上运行,而 nginx 在 80 上运行,当请求传入时,nginx 将对 nodejs 进行代理。 (我已将 nginx.conf 与代理定义为 3000)。
它发生在 Fargate 模式下。但是我这里没有选择,网络模式只有awsvpc。
我能做什么?有没有办法在容器之间进行链接?一个conatiner,nginx和nodejs里面?只是nodejs?其他解决方案?
这里是我的 terraform 设置:
resource "aws_ecs_service" "nginx" {
name = "nginx-${var.app}"
cluster = aws_ecs_cluster.demo.id
task_definition = aws_ecs_task_definition.nginx.arn
desired_count = 4
launch_type = "FARGATE"
lifecycle {
ignore_changes = [task_definition]
}
...
}
resource "aws_ecs_task_definition" "nginx" {
family = "nginx-${var.app}"
container_definitions = file("container_definitions.json")
requires_compatibilities = ["FARGATE"]
network_mode = "awsvpc"
}
container_definitions.json:
[
{
"name": "nginx-...nginx-www",
"image": "311443.dkr.ecr.us-east-2.amazonaws.com/...-nginx:latest",
"cpu": 256,
"memory": 256,
"essential": true,
"links": ["www-app"],
"portMappings": [
{
"protocol": "tcp",
"containerPort": 80
}
],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "...",
"awslogs-region": "us-east-2",
"awslogs-stream-prefix": "ecs"
}
}
},
{
"name": "www-app",
"image": "93934.dkr.ecr.us-east-2.amazonaws.com/..../www-app:latest",
"cpu": 256,
"memory": 256,
"essential": true,
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/ecs-..../nginx",
"awslogs-region": "us-east-2",
"awslogs-stream-prefix": "ecs"
}
}
}
]
【问题讨论】:
-
我认为这是来自远程 ECS API 而不是来自 Terraform 的错误,在这种情况下,其他问题的答案可能会有所帮助:Docker links with awsvpc network mode
标签: node.js nginx terraform terraform-provider-aws