This chapter, we will zyproject-configserver project published to the server through a docker. build process zyproject-configserver See: " Micro Services Migration note (c): to build distribution center SpringCloud Config "
First, the environment Introduction
Server 192.168.0.12 docker has been to build a good environment, and can access through port 2375.
bootstrap-prd.yml 配置:
consul address: http: //192.168.0.12: 8500
Database address: 192.168.0.7
We will publish the next service to 192.168.0.12 container / home / app directory and run.
Second, publish the configuration
1. Create a docker (file-> setting-> Build, Execution, Deployment-> docker) in idea, enter the server address and port, and prompts "Connection successful"
2. The parent pom project referenced docker configuration
<!--docker配置--> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <executions> <execution> <id>default</id> <goals> <goal>build</goal> <goal>push</goal> </goals> </execution> </executions> <configuration> <imageName>${project.artifactId}</imageName> <imageTags> imagetag<>latest</imageTag> </imageTags> <buildArgs> <JAR_FILE>${project.build.finalName}.jar</JAR_FILE> </buildArgs> </configuration> </plugin> </plugins> </build>
zyproject-configserver project only need to reference the maven plug-ins
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> </plugin> </plugins>
3. Create the root directory Dockerfile zyproject-configserver and configure the content
The Java the FROM: 8 ARG JRE_FILE ENV PROFILE prd the ADD target / * .jar /home/app/config.jar ! # EXPOSE command only declared the container should open ports did not actually open it # We are no way in which Dockerfile port mapping, we can only use or to specify the ports in the docker-compose documents when the container starts to be mapped port EXPOSE 8000 EntryPoint the Java $ {} -Djava.security.egd the JAVA_OPTS = file: / dev /./ urandom -Duser.timezone = Asia / Shanghai -Dfile.encoding = UTF-8 -Dspring.profile.active = $ {PROFILE} -jar /home/app/config.jar
4. Packing performed maven package
5. Edit the idea of configuration, add a docker publication items
Note: Dockerfile does not bring the container port mapping to an external server port, so we configured in the Configuration port mapping 8000-> 8000 (the same config best inside and outside, otherwise it will not find the registry service)
6. Start publishing, select just the new docker to run. Can be seen in the publishing and container tomcat running log in below
Access: http://192.168.0.12:8000/actuator/health
{
status: "UP"
}
Of course, you can also log server, using the docker command to check the status of the container.
Reference: " server docker frequently used commands ."