目录
新增Dockerfile文件,并docker远程部署
/        

新增Dockerfile文件,并docker远程部署

基于此项目:https://github.com/MrNiebit/ExpressTrace/tree/master/backend

本机设置

  1. idea安装Docker插件,一般是自带 的。
  2. 在项目根目录下创建Dockerfile文件,文件名一般固定为Dockerfile
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"]
  1. maven配置插件
<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>

docker端的设置

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

使用idea上的插件连接docker

0FOpQ0.png

然后允许 dockerfile文件 build 构建


标题:新增Dockerfile文件,并docker远程部署
作者:MrNiebit
地址:https://blog.lacknb.cn/articles/2020/10/07/1602034218647.html

Gitalking ...