title: Spring Cloud Consul and Consul Clients dockerized
body: <p>I have 2 applications, both written using spring boot. Both are running in different docker containers. I also have consul running in a different docker container. I have exposed port 8500 for consul using docker-compose.yml file. So, how do I specify to my spring boot applications where to register themselves, i.e, where is consul running. Do I give the address of the mapped port (port mapped to my local machine), or some other change?</p>
  
  <p>The example I'm using right now: <a href="https://github.com/Java-Techie-jt/cloud-consul-service-discovery" rel="nofollow noreferrer">https://github.com/Java-Techie-jt/cloud-consul-service-discovery</a></p>
  
  <p>Edit:</p>
  
  <p>docker-compose.yml:</p>
  
  <pre><code>version: "2"
  
  services:
    consul:
      container_name: consul
      image: consul
      expose:
        - "8300"
        - "8400"
        - "8500"
      restart: always
    registrator:
      container_name: registrator
      image: gliderlabs/registrator:master
      volumes:
        - "/var/run/docker.sock:/tmp/docker.sock"
      command: -internal consul://consul:8500
      restart: always
      depends_on:
        - consul
    web1:
      image: deis/mock-http-server
      container_name: web1
      expose:
        - "8080"
      environment:
        SERVICE_NAME: "web"
        SERVICE_TAGS: "web"
      restart: always
      depends_on:
        - registrator
    web2:
      image: deis/mock-http-server
      container_name: web2
      expose:
        - "8080"
      environment:
        SERVICE_8080_NAME: "web"
        SERVICE_8080_TAGS: "web"
      restart: always
      depends_on:
        - registrator
    haproxy:
      build: ./haproxy
      container_name: my-haproxy
      image: anthcourtney/haproxy-consul
      ports:
        - 80
      depends_on:
        - web1
        - web2
    test:
      container_name: test-client
      build: ./test
      depends_on:
        - haproxy
  
  networks:
    default:
  </code></pre>