In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces Docker Compose how to deploy complex App, the content is very detailed, interested friends can refer to, hope to be helpful to you.
How to deploy complex application using docker-compose.
Let's start with some simple commands for docker-compose:
Docker-compose build
This command builds the service image based on the contents of the docker-compose.yml file.
Docker-compose up
This command starts all services.
Docker-compose down-rmi all
Stop the docker-compose container and delete the corresponding container image.
First, take a look at the system architecture:
Each microservice is implemented using springboot.
Eureka service
His application.properties is as follows:
Whether server.port=8080eureka.instance.hostname=192.168.182.151# registers itself with the service center and whether eureka.client.register-with-eureka=false# retrieves the service eureka.client.fetch-registry=falseeureka.client.service-url.defaultZone= http://${eureka.instance.hostname}:${server.port}/eureka/elasticsearch-curl service
The application.properties content is as follows:
Spring.elasticsearch.rest.uris=192.168.182.149:9200logging.level.root=INFOlogging.file=user.loges.ips [0] = registered address of the 192.168.182.149es.port=9300es.clusterName=elasticsearch# registry eureka.client.service-url.defaultZone= http://192.168.182.151:8080/eureka/spring.application.name=elasticsearch-curl-providerserver.port=8081es-consumer service
This service is mainly used to consume es-curl services. His application.propertis is as follows:
# the registered address of the registry eureka.client.service-url.defaultZone= http://192.168.182.151:8080/eureka/spring.application.name=elasticsearch-consumerserver.port=8082
Invoke the service:
ResponseEntity objectResponseEntity = restTemplate.postForEntity ("http://elasticsearch-curl-provider/add/"+indexName+"/" + type, data, Object.class); contents of the Dockerfile file
Eureka Service:
FROM java:8-alpineMAINTAINER "eureka server" ADD spring-cloud-eureka-server-1.0-SNAPSHOT.jar app.jarEXPOSE 8080ENTRYPOINT ["java", "- jar", "/ app.jar"]
Es-curl Service:
FROM java:8-alpineMAINTAINER "es-curl server" ADD elasticsearch-curl-1.0-SNAPSHOT.jar app.jarEXPOSE 8081ENTRYPOINT ["java", "- jar", "/ app.jar"]
Es-consumer Service:
FROM java:8-alpineMAINTAINER "es-curl server" ADD elasticsearch-curl-1.0-SNAPSHOT.jar app.jarEXPOSE 8081ENTRYPOINT ["java", "- jar" "/ app.jar"] docker-compose.yml file version: '3'services: eureka: build: context:. / eureka dockerfile: Dockerfile container_name: ddy-eureka ports:-"8080 es-curl: build: context:. / es-curl/. Dockerfile: Dockerfile container_name: ddy-es-curl depends_on:-eureka ports:-"8081 ddy-es-curl depends_on 8081" links:-eureka es-consumer: build: context:. / es-consumer/. Dockerfile: Dockerfile container_name: ddy-consumer depends_on:-eureka-es-curl ports:-"8082 eureka 8082" links:-eureka-es-curl Operation docker-compose builddocker-compose up
Visit 192.168.182.151Vol 8080
A better way to deploy
In the eureka service, modify the application.properties content:
Eureka.instance.hostname=eureka
Modify the contents of the application.properties in the es-curl and es-consumer services respectively:
Eureka.client.service-url.defaultZone= http://eureka:8080/eureka/
So you don't need to know what the ip of the host is.
Experiment 2: test simple eureka producers and consumers:
Project code: under the eureka directory under https://github.com/vincentduan/spring-cloud-project
Eureka server
The content of application.properties in eureka server is as follows:
Whether server.port=8080eureka.instance.hostname=eureka# registers its own eureka.client.register-with-eureka=false# with the service center and whether to retrieve the service eureka.client.fetch-registry=falseeureka.client.service-url.defaultZone= http://${eureka.instance.hostname}:${server.port}/eureka/
The corresponding Dockerfile content is as follows:
FROM java:8-alpineMAINTAINER "es-curl server" ADD spring-cloud-eureka-server-1.0-SNAPSHOT.jar app.jarEXPOSE 8080ENTRYPOINT ["java", "- jar", "/ app.jar"] service-provider1
The content of application.properties in service-provider1 is as follows:
# Registration address of the registry eureka.client.service-url.defaultZone= http://eureka:8080/eureka/# service name-- the method spring.application.name=service-provider-Aserver.port=8081 that invokes the service based on its name when called
The corresponding Dockerfile content is as follows:
FROM java:8-alpineMAINTAINER "es-curl server" ADD spring-cloud-eureka-provider-A-1-1.0-SNAPSHOT.jar app.jarEXPOSE 8081ENTRYPOINT ["java", "- jar", "/ app.jar"] service-provider2
The content of application.properties in service-provider2 is as follows:
# Registration address of the registry eureka.client.service-url.defaultZone= http://eureka:8080/eureka/# service name-- the method spring.application.name=service-provider-Aserver.port=8082 that invokes the service based on its name when called
The contents of the Dockerfile are as follows:
FROM java:8-alpineMAINTAINER "es-curl server" ADD spring-cloud-eureka-provider-A-2-1.0-SNAPSHOT.jar app.jarEXPOSE 8082ENTRYPOINT ["java", "- jar", "/ app.jar"] consumer
The content of application.properties in consumer is as follows:
# Registration address of the registry eureka.client.service-url.defaultZone= http://eureka:8080/eureka/# service name-- the method spring.application.name=service-consumer-Aserver.port=8083 that invokes the service based on its name when called
The contents of the Dockerfile are as follows:
# Registration address of the registry eureka.client.service-url.defaultZone= http://eureka:8080/eureka/# service name-- the method spring.application.name=service-consumer-Aserver.port=8083 that invokes the service based on its name when called
The entire docker-compose.yml file is as follows:
Version: '3'services: eureka: build: context:. / eureka dockerfile: Dockerfile container_name: ddy-eureka ports:-"8080 build" service-provider-1: build: context:. / provider-1 dockerfile: Dockerfile container_name: ddy-provider-1 ports: -"8081" depends_on:-eureka links:-eureka service-provider-2: build: context:. / provider-2 dockerfile: Dockerfile container_name: ddy-provider-2 ports:-"8082" depends_on: -eureka links:-eureka service-consumer: build: context:. / consumer dockerfile: Dockerfile container_name: ddy-consumer ports:-"8083 build 8083" depends_on:-eureka-service-provider-1-service-provider-2 Links:-eureka-service-provider-1-service-provider-2
Execute docker-compose build to perform the build.
Use the command docker-compose ps to view the service:
Docker-compose ps Name Command State Ports-ddy-consumer java-jar / app.jar Up 0.0.0.0 : 8083-> 8083/tcpddy-eureka java-jar / app.jar Up 0.0.0.0 app.jar Up 8080-> 8080/tcpddy-provider-1 java-jar / app.jar Up 0.0.0.0 app.jar Up 8081-> 8081/tcpddy-provider-2 java-jar / app.jar Up 0.0.0.0 app.jar Up 8082-> 8082/tcp
Docker-compose up starts the project.
Enter the ip address in the browser: ip:8080 can see that the eureka service has been started. And you can see that provider is already registered. Enter ip:8083/gotoUser/jack to swipe several times to see that different provider services are enabled.
On how to deploy complex Docker Compose App to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.