Copyright NOTICE: Welcome reprint, please indicate the source, thank you. http://blog.csdn.net/boling_cavalry/article/details/79177930
Directory (?) [+]
Starting from this chapter, we work with the development and deployment of the spring cloud under Docker, the entire combat is divided into the following three chapters:
1. Docker under the Speed Experience Registration center, service providers, service consumers;
2. Elaborate on spring cloud development;
3. Actual combat expansion;
This chapter is the first of the trilogy, we use the shortest time, the simplest to do together under the Docker Experience Springcloud Registration Center, service providers, service consumers;
Original address: http://blog.csdn.net/boling_cavalry/article/details/79177930
Combat environment
This real-time network machine information such as:
Actual content
This combat environment provides the following services:
1. Eureka is a registered centre;
2. Provider registration to Eureka after startup;
3. Consumer registration to Eureka after startup;
4. Browser access to consumer controller;
5. Consumer receives the request, obtains the provider address through the Eureka, then sends the request to provider;
6. Provider returns a string to consumer with the IP address of the provider in the string;
7. Consumer the string back to the browser;
Container information
The Eureka, provider, and consumer in the environment are all Docker containers, and their names and IPs are shown in the following table:
Container name |
IP |
function |
Springcloud_eureka_1 |
172.17.0.2 |
Registration Center |
Springcloud_provider_1 |
172.17.0.3 |
Provision of services |
Springcloud_consumer_1 |
172.17.0.4 |
Provides the HTTP interface for browser access, and the corresponding response invokes provider's service |
Software information
The environmental information of this actual combat is as follows:
1. Operating system: UBUNTU16;
2. Docker version: 17.03.2-ce;
3. jdk:1.8.0_161;
Docker-compose Configuration
Create a docker-compose.yml file that reads as follows:
Eureka:image:bolingcavalry/eureka-server:0.0.1-snapshot ports: -" 8081:8080 "TTY: trueprovider:image:bolingcavalry/service-provider: 0.0.1-SNAPSHOT Links: -eureka:eurekahost TTY: trueconsumer:image:bolingcavalry/service< Span class= "Hljs-attribute" >-consumer:0.0.1-snapshot Links: -eureka:eurekahost ports: - Span class= "hljs-string" > "8083:8080" TTY: true
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
Start container
Start all containers by executing the following command in the directory where the DOCKER-COMPOSE.YML is located:
sudo docker-compose up -d
The console displays the following information at startup:
[email protected]129-56-ubuntu:~/work/springcloud$ clearCreating springcloud_eureka_1 ... doneCreating springcloud_eureka_1 ... Creating springcloud_consumer_1 ... doneCreating springcloud_provider_1 ... done
Execute the command sudo docker logs-f springcloud_eureka_1 to see the registry launch, and see the following information to indicate that the registry was successful:
2018-01-2616:56:52.540 INFO1---[thread-Each] C. n. E. R. Peerawareinstanceregistryimpl:got1 instances from neighboring DS node2018-01-2616:56:52.540 INFO1---[thread-Each] C. n. E. R. Peerawareinstanceregistryimpl:renew threshold is:12018-01-2616:56:52.540 INFO1---[thread-Each] C. n. E. R. Peerawareinstanceregistryimpl:changing status to Up2018-01-26 16: 56:52.601 INFO 1---[Thread-11] e.s2018- 01-26 16: 56:52.833 INFO 1---[main] S.b.c.e.t8080 (http)
Execute the command sudo docker logs-f springcloud_provider_1 Check the service provider's startup situation and see the following information to indicate that the service provider started successfully:
2018-01-2616:56:51.826 INFO1---[main] s. b. C. E. t. Tomcatembeddedservletcontainer:tomcat started on port (s):8080 (http)2018-01-2616:56:51.833 INFO1---[main] .s.c.n.e.s80802018-01-26 16:56:< Span class= "Hljs-number" >51.871 INFO 1---[main] c.b.sin 58.522 seconds (JVM running for 62.865)
Execute the command sudo docker logs-f springcloud_consumer_1 View the service consumer's startup situation and see the following information to indicate that the service consumer started successfully:
2018-01-2616:56:54.097 INFO1---[nforeplicator-0]Com. Netflix. Discovery. Discoveryclient:discoveryclient_service-consumer/d39efe3da1c0:service-consumer:8080:registering service ...2018-01-2616:56:54.649 INFO1---[main] s. b. C. E. t. Tomcatembeddedservletcontainer:tomcat started on port (s):8080 (http)2018-01-2616:56:54.655 INFO1---[main] .s.c.n.e.s80802018-01-26 16:56:< Span class= "Hljs-number" >54.676 INFO 1---[main] c.b.sin 61.268 seconds (JVM running for 65.699)
Verify
Visit http://localhost:8081/to see the first page of the registry, as shown in the red box indicating that both the service provider and the consumer are connected to the registry:
Access HTTP://WWW.BOLINGCAVALRY.COM:8083/USER/AAA/BBB can invoke the Web page of the service consumer server, where the service consumer invokes the service provider's service, and the service provider's response is the user's name and ID information. As well as your own IP address, consumer receives this information and returns to the webpage, such as:
At this point, we have a quick experience of Springcloud's registry and the provision and consumption of services under Docker, and in the next chapters we will expand the implementation of these features;
One of the Spring Cloud Trilogy under Docker: the Speed Experience