title: Register multiple Instances of a Spring Boot Eureka Client from a single host
body: <p><strong>UPDATE</strong> </p>
  
  <p>The README in <a href="https://github.com/mcwumbly/spring-boot-eureka-example" rel="nofollow">this repo</a> has been updated to demonstrate the solution in the accepted answer.</p>
  
  <hr>
  
  <p>I'm working with a simple example of a Spring Boot Eureka service registration and discovery based on <a href="https://spring.io/guides/gs/service-registration-and-discovery/" rel="nofollow">this guide</a>.</p>
  
  <p>If I start up one client instance, it registers properly, and it can see itself through the <code>DiscoveryClient</code>.  If I start up a second instance with a different name, it works as well.</p>
  
  <p>But if I start up two instances with the same name, the dashboard only shows 1 instance running, and the <code>DiscoveryClient</code> only shows the second instance.</p>
  
  <p>When I kill the 2nd instance, the 1st one is visible again through the dashboard and the discovery client.</p>
  
  <p>Here are some more details about the steps I'm taking and what I'm seeing:</p>
  
  <p><strong>Eureka Server</strong></p>
  
  <p>Start the server</p>
  
  <pre><code>cd eureka-server
  mvn spring-boot:run
  </code></pre>
  
  <p>Visit the Eureka dashboard at <a href="http://localhost:8761" rel="nofollow">http://localhost:8761</a></p>
  
  <p>Note that there are no 'Instances' yet registered</p>
  
  <p><strong>Eureka Client</strong></p>
  
  <p>Start up a client</p>
  
  <pre><code>cd eureka-client
  mvn spring-boot:run
  </code></pre>
  
  <p>Visit the client directly at <a href="http://localhost:8080/" rel="nofollow">http://localhost:8080/</a></p>
  
  <p>The <code>/whoami</code> endpoint will show the client's self-knowledge of its application name and port</p>
  
  <pre><code>{
    "springApplicationName":"eureka-client",
    "serverPort":"8080"
  }
  </code></pre>
  
  <p>The <code>/instances</code> endpoint will take up to a minute to update, but should eventually show all the instances of <code>eureka-client</code> that have been registered with the Eureka Discovery Client.</p>
  
  <pre><code>[   
      {
        "host":"hostname",
        "port":8080,
        "serviceId":"EUREKA-CLIENT",
        "uri":"http://hostname:8080",
        "secure":false   
      } 
  ]
  </code></pre>
  
  <p>You can also visit the Eureka dashoboard again now and see it listed there.</p>
  
  <p><strong>Spin up another client with a different name</strong></p>
  
  <p>You can see that another client will be registred by doing the following:</p>
  
  <pre><code>cd eureka-client
  mvn spring-boot:run -Dspring.application.name=foo -Dserver.port=8081
  </code></pre>
  
  <p>The <code>/whoami</code> endpoint will show the name <code>foo</code> and the port <code>8081</code>.</p>
  
  <p>In a minute or so, the <code>/instances</code> endpoint will show the information about this <code>foo</code> instance too.</p>
  
  <p>On the Eureka dashboard, two clients will now be registered.</p>
  
  <p><strong>Spin up another client with the <em>same</em> name</strong></p>
  
  <p>Now try spinning up another instance of <code>eureka-client</code> by only over-riding the port parameter:</p>
  
  <pre><code>cd eureka-client
  mvn spring-boot:run -Dserver.port=8082
  </code></pre>
  
  <p>The <code>/whoami</code> endpoint for <code>http://localhost:8082</code> shows what we expect.</p>
  
  <p>In a minute or so, the <code>/instances</code> endpoint now shows the instance running on port 8082 also, but for some reason, it doesn't show the instance running on port 8080.</p>
  
  <p>And if we check the <code>/instances</code> endpoint on <code>http://localhost:8080</code> we also now only see the instance running on 8082 (even though clearly, the one on 8080 is running since that's what we're asking for.</p>
  
  <p>The Eureka dashboard only shows 1 instance of <code>eureka-client</code> running.</p>
  
  <p>What's going on here?</p>
  
  <p>Let's try killing the instance running on 8082 and see what happens.</p>
  
  <p>When we query <code>/instances</code> on 8080, it still only shows the instance on 8082.</p>
  
  <p>But a minute later, that goes away and we just see the instance on 8080 again.</p>
  
  <p>The question is, why don't we see both instances of <code>eureka-client</code> when they are both running?</p>