Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Microservice dockerization of docker in Advanced articles (18)

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Original articles, welcome to reprint. Reprint please indicate: reproduced from IT Story Association, thank you!

Original link address: "Advanced article" docker's microservice dockerization (18)

This time into the deployment of micro-services, the code is also basically passed. If compared to a song, the prelude is over, now let's start our best part, if we use docker for our service, use the service orchestration tool to get the project up and running. Source code: https://github.com/limingios/msA-docker

Be careful

Because the docker words are all in the linux environment, in order to facilitate the preparation of dockerfile files, I switched to the mac book for demonstration, only for a convenient development of sh. Easy to use. Mac is the first choice for CICD learning practice.

The microservice deployment service is dockerized and can be run under docker. The Docker repository is created, and the image push created by docker is put into the repository. Build a highly available cluster environment, Mesos,Swarm,kubernetes. Run these three service orchestration tools to run and orchestrate our services. Can gracefully start, stop, expand capacity, fault recovery. Docker

Service has a suitable environment, service can run, prepare an environment for him, for example, service is a seed, we need to prepare a piece of land, service is a fish, we need to prepare a sea. One of the services in the source code is written by python and one is written by java, which requires two runtime environments, one based on java and the other based on python.

Java Mirror

Go to hub.docker.com to search java and find tag.

Download java image

Configure acceleration first, https://www.daocloud.io/mirror

Docker pull java:openjdk-8 docker images | grep jdk

Install jdk container docker run-it-- entrypoint bash java:openjdk-8java-version

Start the development of dockerfile

People who are familiar with docker should know that if you want to compile docker, you need docker, and you first need to develop dockerfile files.

Preparatory work

There can be no dead writing in the file. If it is written dead, the mirror image needs to be changed every time the service is changed. In order to reduce the process of building a mirror, try to change the access address of the database. You need to kick out the things that often change. Do not configure dead in the configuration file. For database access, you cannot write the address directly. Mysql's address, when the service runs on docker, his ip is changing in real time, and cannot be written to death in the image. If you can't find it, you will report an error. There is also a question of what form our services should be put in our docker. Springboot has a great advantage because it can build our services into a fat jar with only one jar package, and then run through a command from java: java-jar file. Jar, this way is also very friendly and very simple for micro services, so use this way. Variables can be passed in via springboot-- mysql.address.

Build user-thrift-service

Modify configuration files and pom.xml files

Application.properties

Configuration of service.name=user-thrift-serviceservice.port=7911# data source spring.datasource.url=jdbc:mysql:// {mysql.address}: 3306/db_userspring.datasource.username=rootspring.datasource.password=rootspring.datasource.driver-class-name=com.mysql.jdbc.Driver

Pom.xml

Org.springframework.boot spring-boot-starter-parent 1.5.3.RELEASE 4.0.0 com.idig8 user-thrift-service 1.0-SNAPSHOT org.springframework.boot spring-boot-starter org.apache.thrift libthrift 0.10.0 Com.idig8 user-thrift-service-api 1.0-SNAPSHOT org.mybatis.spring.boot mybatis-spring-boot-starter 1.3.1 mysql mysql-connector-java 5.1.44 Org.apache.maven.plugins maven-compiler-plugin 2.3.2 1.8 1.8 org.springframework.boot spring-boot-maven-plugin Repackage

Dockfile writing

FROM java:openjdk-8MAINTAINER liming www.idig8.comCOPY target/user-thrift-service-1.0-SNAPSHOT.jar / user-thrift-service.jarENTRYPOINT ["java", "- jar", "/ user-thrift-service.jar"]

Execute build to generate an image

Docker build-t user-thrift-service:latest.

View ip addr

Ifconfig

Generate Container

Docker run-it user-thrift-service:latest-- mysql.address=192.168.1.140

Newly established build.sh

#! / usr/bin/env bash

Mvn package

Docker build-t user-thrift-service:latest.

! [] (https://upload-images.jianshu.io/upload_images/11223715-966e41457da6513c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)* builds message-thrift-python-service > a lot of services that depend on it, and must be done well. It is a python service, we need to find a python image. Go to the official search for ````bash docker pull python:3.6 docker images | grep python

Write Dockerfile

FROM python:3.6MAINTAINER liming www.idig8.comRUN pip install thriftENV PYTHONPATH / COPY message/ messageENTRYPOINT ["python", "/ message/message_service.py"]

Docker build-t message-thrift-python-service:latest.

Build development

#! / usr/bin/env bashdocker build-t message-thrift-python-service:latest.

Image generation container

Docker run-it message-thrift-python-service:latest

Build user-edge-service

Depending on micro-services, people who know docker should know that you can search for this service by name through link, as long as it is not within the scope of development, it is considered to be another way of intervention, ip, domain name. There are two kinds of docker: the communication between micro-service and micro-service, and the communication between micro-service and peripheral system.

Modify configuration files and pom.xml files

Application.properties

Server.name=user-edge-serviceserver.port=8082thrift.user.ip=user-thrift-servicethrift.user.port=7911thrift.message.ip=message-thrift-python-servicethrift.message.port=9090#redis configspring.redis.host=$ {redis.address} spring.redis.port=6379spring.redis.password=limingspring.redis.timeout=30000

Pom.xml

Org.springframework.boot spring-boot-starter-parent 1.5.3.RELEASE 4.0.0 com.idig8 user-edge-service 1.0-SNAPSHOT org.springframework.boot spring-boot-starter-web org.apache.thrift libthrift 0.10.0 Com.idig8 user-thrift-service-api 1.0-SNAPSHOT com.idig8 message-thrift-service-api 1.0-SNAPSHOT org.springframework.boot spring-boot-starter-data-redis commons-lang Commons-lang 2.6 org.springframework.boot spring-boot-starter-thymeleaf org.apache.maven.plugins maven-compiler-plugin 2.3.2 1.8 1.8 org.springframework.boot spring-boot-maven-plugin repackage

Dockerfile writing

FROM java:openjdk-8MAINTAINER liming www.idig8.comCOPY target/user-edge-service-1.0-SNAPSHOT.jar / user-edge-service.jarENTRYPOINT ["java", "- jar", "/ user-edge-service.jar"]

Build.sh writing

#! / usr/bin/env bashmvn packagedocker build-t user-edge-service:latest.

Sh build.sh

Create a container

Docker run-it user-edge-service:latest-- redis.address=192.168.1.140

Build course-dubbo-service

Depending on micro-services, people who know docker should know that you can search for this service by name through link, as long as it is not within the scope of development, it is considered to be another way of intervention, ip, domain name. There are two kinds of docker: the communication between micro-service and micro-service, and the communication between micro-service and peripheral system.

Modify configuration files and pom.xml files

Application.properties

# dubbo configuration spring.dubbo.application.name=course-dubbo-servicespring.dubbo.registry.address=zookeeper://$ {zookeeper.address}: configuration of 2181spring.dubbo.protocol.name=dubbospring.dubbo.protocol.port=20880#spring.dubbo.protocol.host=127.0.0.1spring.dubbo.scan=com.idig8.course# data sources spring.datasource.url=jdbc:mysql://$ {mysql.address}: 3306/db_coursespring.datasource.username=rootspring.datasource.password=rootspring.datasource.driver-class-name=com.mysql.jdbc.Driverthrift.user.ip=user-thrift-servicethrift.user.port=7911

Pom.xml

Org.springframework.boot spring-boot-starter-parent 1.5.3.RELEASE 4.0.0 com.idig8 course-dubbo-service 1.0-SNAPSHOT io.dubbo.springboot spring-boot-starter-dubbo 1.0.0 org.springframework.boot spring-boot-starter Org.apache.thrift libthrift 0.10.0 org.mybatis.spring.boot mybatis-spring-boot-starter 1.3.1 mysql mysql-connector-java 5.1.44 com. Idig8 course-dubbo-service-api 1.0-SNAPSHOT com.idig8 user-thrift-service 1.0-SNAPSHOT com.idig8 user-thrift-service-api 1.0-SNAPSHOT Org.apache.maven.plugins maven-compiler-plugin 2.3.2 1.8 1.8 org.springframework.boot spring-boot-maven-plugin Repackage

Dockerfile writing

FROM java:openjdk-8MAINTAINER liming www.idig8.comCOPY target/course-dubbo-service-1.0-SNAPSHOT.jar / course-dubbo-service.jarENTRYPOINT ["java", "- jar", "/ course-dubbo-service.jar"]

Build.sh writing

#! / usr/bin/env bashmvn packagedocker build-t course-dubbo-service:latest .sh build.sh

Create a container

Docker run-it course-dubbo-service:latest-redis.address=192.168.1.140-zookeeper.address=192.168.1.140

Build course-edge-service

It's basically the same as between them, and it's all repetitive work. Just look at the source code.

Modify pom file add maven build add dockerfile file add build.sh file resource file modification

Docker run-it course-edge-service:latest-- zookeeper.address=192.168.1.140

Docker run-it gataway-zuul:latest

PS: make all the individual services into images, and next time find a way to run the services and images together.

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report