Eureka: example of creating 3 nodes Eureka Server with docker

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。


In this artical, it will state how to create 3 nodes Eureka Server with docker.

Step1. Create Eureka Server


We will create 3 Eureka Servers which is named as "peer1", "peer2", "peer3" respectively, with register order as peer1 -> peer2, peer2 -> peer3 and peer3 -> peer1

docker network create eureka-net
docker run -it --name peer_host_1 --net eureka-net --rm -e EUREKA_SERVER_HOSTNAME=peer_host_1 -e EUREKA_SERVER_PORT=8761 -e EUREKA_SERVER_PEER_URL=, -p 8761:8761 -d yexianyi/eureka-server
docker run -it --name peer_host_2 --net eureka-net --rm -e EUREKA_SERVER_HOSTNAME=peer_host_2 -e EUREKA_SERVER_PORT=8762 -e EUREKA_SERVER_PEER_URL=, -p 8762:8762 -d yexianyi/eureka-server
docker run -it --name peer_host_3 --net eureka-net --rm -e EUREKA_SERVER_HOSTNAME=peer_host_3 -e EUREKA_SERVER_PORT=8763 -e EUREKA_SERVER_PEER_URL=, -p 8763:8763 -d yexianyi/eureka-server


1. is my local host which installed docker engine

2. EUREKA_SERVER_HOSTNAME: this name will be mapping to attribute "eureka.instance.hostname" . Must be unique, otherwise eureka replicas will not be functional.

3. In order to access Eureka Dashboard of each node, each docker container exposed EUREKA_SERVER_PORT.

Once all these 3 server start up, we can visit their dashboards via and Each of dashboard should be similiar to following screenshot:


Step 2. Register Service

After Eureka Server Cluster we created is done, we can register some services on it. Here, I will use an existing demo service to show it.


docker run --rm -it --net eureka-net -e EUREKA_PROVIDER_PORT=8800 -e EUREKA_SERVER_PEER_URL= -d yexianyi/eureka-provider
docker run --rm -it --net eureka-net -e EUREKA_PROVIDER_PORT=8801 -e EUREKA_SERVER_PEER_URL= -d yexianyi/eureka-provider
docker run --rm -it --net eureka-net -e EUREKA_PROVIDER_PORT=8802 -e EUREKA_SERVER_PEER_URL= -d yexianyi/eureka-provider

Now, we can see that 3 copy of "HELLO-SERVICE" have been registered to the registry with port from 8800 to 8802. And these update have been populated to 2 other eureka server peer_host_2 and peer_host_3.



Step 3. Develop Eureka Service Consumer

Now, we will deploy an eureka consumer to access HELLO-SERVICE.


docker run --rm -it -e EUREKA_CONSUMER_PORT=8900 -e EUREKA_SERVER_PEER_URL= -p 8900:8900 -d yexianyi/eureka-consumer

 After that, we will see the consumer "RIBBON-CONSUMER" has been registered in registry.


Step 4. Testing

Given that we have registered service on Eureka, let's test it now.

curl -X GET -i 'http://localhost:8900/ribbon-consumer?message=abc'
curl -X GET -i 'http://localhost:8900/ribbon-consumer?message=abc'
curl -X GET -i 'http://localhost:8900/ribbon-consumer?message=abc'

We will see the response is :

b5fe6b02f0e3:8800 - recv: 'abc'

e152e3d76ecb:8801 - recv: 'abc'

e152e3d76ecb:8802 - recv: 'abc'



Since we created an user-defined network in docker to run all the eureka container in our case, we need to enable ipv4 forwarding function. Otherwise, our container cannot be accessed from outside world.

MAC: sudo sysctl -w net.inet.ip.forwarding=1