title: resolve service hostname in ECS fargate task
body: <p>I am trying to automate my ECS fargate cluster making using terraform.</p>
  <p>I have a SpringBoot project with microservices containerized, and I am putting these images in a single task definition for an ECS service for the backend.</p>
  <p>The ECS cluster is initially running, but Kafka is getting stopped with the error :</p>
  <pre class="lang-sh prettyprint-override"><code>ERROR Unable to resolve address: zookeeper:2181
  (org.apache.zookeeper.client.StaticHostProvider)
  </code></pre>
  <p>I have given the image for <em>zookeeper(bitnami)</em> and used the KAFKA_CFG_ZOOKEEPER_CONNECT environment variable too.</p>
  <p>EDIT : My task definition:</p>
  <pre><code>resource &quot;aws_ecs_task_definition&quot; &quot;this&quot; {
    family                   = local.application_name
    requires_compatibilities = [local.launch_type]
    execution_role_arn       = data.aws_iam_role.ecs_task_execution_role.arn
    network_mode             = &quot;awsvpc&quot;
    cpu                      = &quot;4096&quot;
    memory                   = &quot;30720&quot;
    container_definitions = jsonencode([
      {
        name      = &quot;zookeeper&quot;
        image     = &quot;docker.io/bitnami/zookeeper:latest&quot;
        essential = true
        cpu       = 512
        memory    = 1024
        portMappings = [
          {
            containerPort = 2181
            hostPort      = 2181
          }
        ]
        &quot;environment&quot; : [
          { &quot;name&quot; : &quot;ALLOW_ANONYMOUS_LOGIN&quot;, &quot;value&quot; : &quot;yes&quot; },
          { &quot;name&quot; : &quot;ZOO_LISTEN_ALLIPS_ENABLED&quot;, &quot;value&quot; : &quot;yes&quot; }
        ]
      },
      {
        name      = &quot;kafka-server&quot;
        image     = &quot;docker.io/bitnami/kafka:latest&quot;
        essential = true
        cpu       = 512
        memory    = 1024
        portMappings = [
          {
            containerPort = 9092
            hostPort      = 9092
          }
        ]
        depends_on =  [
          &quot;zookeeper&quot;
        ]
        &quot;environment&quot; : [
          { &quot;name&quot; : &quot;KAFKA_CFG_ZOOKEEPER_CONNECT&quot;, &quot;value&quot; : &quot;zookeeper:2181&quot; },
          { &quot;name&quot; : &quot;ALLOW_ANONYMOUS_LOGIN&quot;, &quot;value&quot; : &quot;yes&quot; },
          { &quot;name&quot; : &quot;ALLOW_PLAINTEXT_LISTENER&quot;, &quot;value&quot; : &quot;yes&quot; }
        ],
      },
      {
        name      = &quot;email-service&quot;
        image     = &quot;my-email-image&quot;
        essential = true
        cpu       = 512
        memory    = 1024
        portMappings = [
          {
            containerPort = 8090
            hostPort      = 8090
          }
        ]
        &quot;environment&quot; : [
          { &quot;name&quot; : &quot;EMAIL_URL&quot;, &quot;value&quot; : &quot;email-service&quot; },
          { &quot;name&quot; : &quot;EMAIL_PORT&quot;, &quot;value&quot; : &quot;8090&quot; },
          { &quot;name&quot; : &quot;KAFKA_URL&quot;, &quot;value&quot; : &quot;kafka-server&quot; },
          { &quot;name&quot; : &quot;KAFKA_PORT&quot;, &quot;value&quot; : &quot;9092&quot; },
        ]
      }
    ])
  }
  </code></pre>