AWS ECS Docker - nginx: [emerg] host not found in upstream AWS ECS Docker - nginx: [emerg] host not found in upstream nginx nginx

AWS ECS Docker - nginx: [emerg] host not found in upstream


I didnĀ“t set the links inside the AWS ECS Task Definition between the php and nginx containers.

To set the links for a container go to NETWORK SETTINGS and then enter the link inside the Links field.


As correctly said by @OnurDemir you cannt use links when your network mode is awsvpc - "networkMode": "awsvpc",.

With this network mode you can call the containers just with their names.

task-definition.json

{    "family": "app-backend",    "containerDefinitions": [        {            "name": "nginx",            "image": "my-url-to-the-docker-image",            "portMappings": [                {                    "containerPort": 80,                    "hostPort": 80,                    "protocol": "tcp"                }            ],            "dependsOn": [                {                    "containerName": "php-fpm",                    "condition": "START"                }            ],            "essential": true        },        {            "name": "php-fpm",            "image": "my-url-to-the-docker-image",            "portMappings": [                {                    "containerPort": 9000                }            ],            "essential": true        }    ],    "executionRoleArn": "ecsTaskExecutionRole",    "cpu": "1024",    "memory": "2048",    "networkMode": "awsvpc"}

Here you can see that:

  1. The nginx container dependsOn the php-fpm container.
  2. When you want to reference the php-fpm container in, f. ex. a vhost file in nginx, you can just call it by its name php-fpm.

Example 1: fastcgi_pass php-fpm:9000;

Another approach, when using AWS Fargate is, that you can just call the loopback 127.0.0.1 or localhost.Described in some AWS blog when using awsvpc the inter-container connection is made as it if all would be on the same machine, even if they are separate containers.

Example 2: fastcgi_pass 127.0.0.1:9000;