pring cloud项目集成docker配置
首先配置pom文件,如下:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.compo.arche.springcloud</groupId>
<artifactId>eurekaserver</artifactId>
<version>0.0.1_base</version><!-- 此处版本号包含大写字母可能会有问题 -->
<packaging>jar</packaging><!-- jar包 -->
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-parent</artifactId>
<version>Camden.SR7</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<docker.repostory>192.168.8.0</docker.repostory><!-- docker 服务器位置 -->
<docker.registry.name>smartmall</docker.registry.name><!-- 名称 -->
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/docker</directory>
<filtering>true</filtering>
<includes>
<include>**/Dockerfile</include>
</includes>
<targetPath>../docker</targetPath>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.13</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
<configuration>
<serverId>harbor</serverId>
<registryUrl>192.168.8.0</registryUrl>
<pushImage>true</pushImage>
<dockerDirectory>target/docker</dockerDirectory>
<imageName>
${docker.repostory}/${docker.registry.name}/${project.artifactId}:${project.version}
</imageName>
<imageTags>
<imageTag>${project.version}</imageTag>
</imageTags>
<resources>
<rescource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</rescource>
</resources>
</configuration>
</plugin>
</plugins>
</build>
</project>
创建在main下面创建一个包名:docker,然后在docker包下创建文件:Dockerfile;注意-没有扩展名
内容如下:
FROM 192.168.8.0/smartmall/java:8u20
MAINTAINER zzz vvv "zzz@xxx.com"
ENV WORK_PATH /home/root
ENV APP_NAME @project.build.finalName@.@project.packaging@
ENV APP_VERSION @project.version@
EXPOSE 9005
COPY $APP_NAME $WORK_PATH/
WORKDIR $WORK_PATH
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom"]
CMD ["-jar", "@project.build.finalName@.@project.packaging@"]
EXPOSE 9005 是设置端口号
spring cloud项目集成docker上传项目到harbor构建的时候遇到的问题
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project order-micro: Compilation failure: Compilation failure:
[ERROR] /root/.jenkins/workspace/smartmallordermicro/src/main/java/com/ctsig/order/base/aspect/WebLogAspect.java:[35,51] -source 1.6 中不支持 diamond 运算符
[ERROR] (请使用 -source 7 或更高版本以启用 diamond 运算符)
[ERROR] /root/.jenkins/workspace/smartmallordermicro/src/main/java/com/ctsig/order/base/config/MyBatisConfig.java:[54,56] -source 1.6 中不支持 diamond 运算符
[ERROR] (请使用 -source 7 或更高版本以启用 diamond 运算符)
[ERROR] /root/.jenkins/workspace/smartmallordermicro/src/main/java/com/ctsig/order/order/controller/PostInfo.java:[98,51] -source 1.6 中不支持 diamond 运算符
[ERROR] (请使用 -source 7 或更高版本以启用 diamond 运算符)
[ERROR] /root/.jenkins/workspace/smartmallordermicro/src/main/java/com/ctsig/order/base/config/DataSourceContextHolder.java:[7,80] -source 1.6 中不支持 diamond 运算符
[ERROR] (请使用 -source 7 或更高版本以启用 diamond 运算符)
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
这个问题主要是代码格式问题,比如:
错误写法:Map<Object,Object> dataSourceMap = new HashMap<>();//此处的“<>”里面没有设置Object
正确写法:Map<Object,Object> dataSourceMap = new HashMap<Object, Object>();
网友评论