在项目中使用Docker Maven Plugin插件远程构建镜像
日常开发过程中,可以在项目的pom.xml
文件中配置Docker容器,这样方便我们直接将项目打包成Docker
镜像,发布到容器中.
在Java项目中配置
在pom.xml
文件中加入以下内容:
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>1.0.0</version>
<configuration>
<imageName>micro-deploy-docker</imageName>
<!--注意 修改成远程服务器地址-->
<dockerHost> http://192.168.10.11:2375</dockerHost>
<!-- Docker file 文件的所在目录 -->
<dockerDirectory>${project.basedir}</dockerDirectory>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.4</version>
</dependency>
</dependencies>
</plugin>
修改Docker的配置
vim /usr/lib/systemd/system/docker.service
在ExecStart=/usr/bin/dockerd
后面加上-H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
ExecReload=/bin/kil ts HUP $MAINPID
项目的Dockerfile
FROM xxx.com/java:8
MAINTAINER xxx <xxx@gamil.com>
2019/8/16
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
COPY ./pro/target/uve-engine-service-0.0.1-SNAPSHOT.jar /app/app.jar
COPY ./pro/start.sh /app
EXPOSE 8288
ENTRYPOINT ["/bin/bash","/app/start.sh"]
Done.
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Yang!