基于此项目:https://github.com/MrNiebit/ExpressTrace/tree/master/backend
FROM java:8
MAINTAINER gitsilence <gitsilence@lacknb.cn>
EXPOSE 8080
ADD *.jar app.jar
ENTRYPOINT ["java", "-Dfile.encoding=utf-8" ,"-Djava.security.egd=file:/dev/./urandom", "-jar", "/app.jar"]
<plugin>
<!--新增的docker maven插件-->
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.13</version>
<configuration>
<!--dockerDirectory 指定 dockerfile的 位置 -->
<!-- <dockerDirectory>src/main/docker</dockerDirectory>-->
<!--镜像名字-->
<imageName>app.jar<!--${docker.image.prefix}/${project.artifactId}--></imageName>
<!--DokcerFile文件地址-->
<dockerDirectory>/slm/</dockerDirectory>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<!--
phase定义成package,goal定义成run,是为了在运行 " mvn package "的时候自动
执行第一个execution节点下的ant任务
-->
<executions>
<execution>
<phase>package</phase>
<configuration>
<tasks>
<copy todir="${project.basedir}" file="target/${project.artifactId}-${project.version}.${project.packaging}">
</copy>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<!--
[INFO] -maven-antrun-plugin:1.8:run (default) @ backend
[WARNING] Parameter tasks is deprecated, use target instead
[INFO] Executing tasks
[copy] Copying 1 file to E:\javaProject\ExpressTrace\backend
-->
</plugin>
vi /usr/lib/systemd/system/docker.service
在这一行 后面新增 -H 0.0.0.0:2375
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock -H tcp://0.0.0.0:2375
然后重启docker
systemctl restart docker
重新加载配置文件
systemctl daemon-reload
然后允许 dockerfile文件 build 构建