title: AWS ECS how to launch containers in private bridge network
body: <p>How do I get docker automatic service discovery working in an AWS ECS EC2 based cluster service?</p>
  
  <p>I have this corresponding <code>docker-compose.yml</code> (which I'm mapping over to a ECS compatible <code>task-definition.json</code> file):</p>
  
  <pre><code>version: "3"
  services:
    elasticsearch:
      image: docker.elastic.co/elasticsearch/elasticsearch:6.2.2
      environment:
        - discovery.type=single-node
    mongo:
      image: mongo:4.0.12
    redis:
      image: redis:5.0.3
    api:
      image: api
      build: .
      command: api.py
      depends_on:
        - elasticsearch
        - mongo
        - redis
      ports:
        - 5000:5000
  </code></pre>
  
  <p>If I launch this with <code>docker-compose up</code> docker-composer will create a new private bridge network. Within this private network "automatic service discovery" is on and service names resolve to service IP addresses. So for example the <em>api</em> can find <em>mongo</em> without knowing its IP by doing a DNS lookup for "mongo". The network is also isolated from other unrelated containers. You can do this manually via <code>docker</code> too like this:</p>
  
  <pre><code>docker network create api-net
  docker run -d --name elasticsearch --net api-net docker.elastic.co/elasticsearch/elasticsearch:6.2.2
  docker run -d --name mongo --net api-net mongo:4.0.12
  ...
  </code></pre>
  
  <p>But I can't figure out how I can achieve the same via AWS ECS multi-container service defined with a <code>task-definition.json</code> file. If I define multiple services with "bridge" networking all containers are launched into the default bridge network and automatic service discovery does not work. I can manually log into the ECS EC2 container instance and set up a private network, but obviously not a workable solution.</p>