title: Micro services Service discovery using Eureka and traefik with docker compose
body: <p>Traefik for dummies question. I am trying to setup spring cloud micro services with docker compose using traefik as reverse proxy.</p>
  
  <p>My aim is micro services should talk to each other via service name (ex: service-registry-app) and traefik should resolve it to ip address. Once this works in local box, I want to extend it to run on AWS ECS.</p>
  
  <p>I have created ana_network using </p>
  
  <pre><code>docker network create ana_network
  </code></pre>
  
  <h2>traefik configuration:</h2>
  
  <p>File: docker-compose.yml</p>
  
  <pre><code>version: '2'
  
  services:
    proxy:
      image: traefik
      command: --api --docker --docker.domain=docker.localhost --logLevel=DEBUG
      networks:
        - ana_network
      ports:
        - "80:80"
        - "8080:8080"
        - "443:443"
      volumes:
        - /var/run/docker.sock:/var/run/docker.sock
        - /dev/null:/traefik.toml
  
  networks:
    ana_network:
      driver: bridge
  </code></pre>
  
  <h2>micro services configuration:</h2>
  
  <p>File: docker-compose.yml</p>
  
  <pre><code>version: '2'
  
  services:
    service-registry:
      image: sqshq/piggymetrics-registry
      restart: always
      networks:
        - web
      expose:
        - "8761"
      labels:
        - "traefik.backend=service-registry-app"
        - "traefik.frontend.rule=Host:service-registry-app.example.com"
      environment:
        CONFIG_SERVICE_PASSWORD: $CONFIG_SERVICE_PASSWORD    
    config-server:
      image: sqshq/piggymetrics-config
      restart: always
      networks:
        - web
      expose:
        - "8888"
      depends_on:
        - service-registry
      environment:
         EUREKA_HOST: service-registry-app.example.com
         EUREKA_PORT: 8761
         CONFIG_SERVICE_PASSWORD: $CONFIG_SERVICE_PASSWORD
  
      labels:
        - "traefik.backend=config-server-app"
        - "traefik.frontend.rule=Host:config-server-app.example.com"    
  networks:
    web:
      external:
        name: ana_network
  </code></pre>
  
  <p>I can access service registry app using curl</p>
  
  <pre><code>curl -H Host:service-registry-app.example.com http://172.21.0.2:8761
  </code></pre>
  
  <p>But config server and api gateway unable to access service registry with above configuration with docker compose and traefik.</p>
  
  <p>What changes I need to do in order make all micro services to be able discover each other and How to extend it to make it work on ECS?</p>
  
  <p>Edit1:</p>
  
  <p>Corrected indentation to move networks section from services to networks, it was a typo. </p>
  
  <p>I am newbie into containers and distributed systems hence I might be asking some naive obvious questions hence it would be great if any traefik for dummies would be very helpful.</p>
  
  <p>Following are the 2 problems I am facing currently,</p>
  
  <p>1) container to container communication - Example, How container 2 (config server in this example) should communicate with container 1 (service-registry), by service name (like service-registry) or any other way and How to access these containers from external world (in this case service registry)?</p>
  
  <p>2) Extending it to make it work in ECS, hence each will have its own task definition and run as a service inside ECS cluster - in this scenario how containers should communicate with each other using traefik?</p>