创建Dockfile
在pom.xml同级目录下新建Dockfile
FROM registry.docker-cn.com/library/openjdk:8-jdk-alpine
MAINTAINER wangchong<w420050757@gmail.com>
ENTRYPOINT ["/usr/bin/java", "-jar", "/usr/share/h3p-ws/app.jar"]
RUN echo "Asia/Shanghai" > /etc/timezone
# Add Maven dependencies (not shaded into the artifact; Docker-cached)
# Add the service itself
ARG JAR_FILE
ADD target/${JAR_FILE} /usr/share/h3p-ws/app.jar
mavean插件配置
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.4.4</version>
<executions>
<execution>
<id>default</id>
<phase>install</phase>
<goals>
<goal>build</goal>
<goal>push</goal>
</goals>
</execution>
</executions>
<configuration>
<repository>10.2.210.130:5000/rails/h3p-ws</repository>
<tag>${project.version}</tag>
<buildArgs>
<JAR_FILE>${project.build.finalName}.jar</JAR_FILE>
</buildArgs>
</configuration>
</plugin>
mvn install
自动将docker镜像推送到docker仓库
容器编排
打开Portainer 管理界面
点击 Add stack
编辑Compose file
version: '3'
services:
h3p-ws:
ports:
- "38680:38680"//发布的端口
image: 10.2.247.230:17002/docker-env/rails/h3p-api:1.0-SNAPSHOT//镜像
networks:
- h3p
deploy:
replicas: 2 //实例副本数
mode: replicated
restart_policy:
condition: on-failure
placement:
constraints: [node.labels.internet == true] //条件
networks:
h3p:
external: true
到此整个部署完成,可以在管理界面随时更新配置