spring boot docker 部署

创建Dockfile

在pom.xml同级目录下新建Dockfile

FROM registry.docker-cn.com/library/openjdk:8-jdk-alpine
MAINTAINER wangchong

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插件配置

            
                com.spotify
                dockerfile-maven-plugin
                1.4.4
                
                    
                        default
                        install
                        
                            build
                            push
                        
                    
                
                
                    10.2.210.130:5000/rails/h3p-ws
                    ${project.version}
                    
                        ${project.build.finalName}.jar
                    
                
            

mvn install 自动将docker镜像推送到docker仓库

容器编排

打开Portainer 管理界面


image.png

点击 Add stack
编辑Compose file


image.png
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

到此整个部署完成,可以在管理界面随时更新配置

你可能感兴趣的:(spring boot docker 部署)