• docker部署本地springboot项目


    官网:https://spring.io/guides/gs/spring-boot-docker/

    参考文档:https://my.oschina.net/AmosWang/blog/2088358

    阿里云docker信息:https://cr.console.aliyun.com/cn-hangzhou/instances/repositories

    1.在项目的pom文件中添加:

                <plugin>
                    <groupId>com.spotify</groupId>
                    <artifactId>dockerfile-maven-plugin</artifactId>
                    <version>1.3.6</version>
                    <configuration>
                        <repository>${docker.image.prefix}/${project.artifactId} 
                        </repository>
                        <buildArgs>
                            <JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
                        </buildArgs>
                    </configuration>
                </plugin>
    
    
    
    <properties>
            <java.version>1.8</java.version>
            <docker.image.prefix>pheony</docker.image.prefix>
    </properties>

    在项目目录下添加Dockerfile文件

    FROM openjdk:8-jdk-alpine
    VOLUME /tmp
    ARG JAR_FILE
    COPY ${JAR_FILE} app.jar
    ENTRYPOINT ["java","-jar","/app.jar"]

    2.项目打包

    idea直接右边栏install即可或mvn install打包,生成文件在target目录下

    3.本地安装docker 打开shell在项目目录下运行:mvn clean package docker:build  

      错误:No plugin found for prefix 'docker' in the current project and in the plugin groups.

                修改 maven 的配置文件 settings.xml

    <pluginGroups>
        <pluginGroup>com.spotify</pluginGroup>
    </pluginGroups>

    错误:Must specify baseImage if dockerDirectory

              使用mvn clean package dockerfile:build

     4.本地镜像上传仓库,服务器上docker拉取

     https://cr.console.aliyun.com/repository/cn-hangzhou/sycamore/sycamore/details

    参照模板,此案例命令:

    本地镜像上传
    docker login --username=darksinco registry.cn-hangzhou.aliyuncs.com
    
    docker tag 854bcdabbe68 house
    
    docker tag 854bcdabbe68 registry.cn-hangzhou.aliyuncs.com/sycamore/sycamore:house
    
    docker push registry.cn-hangzhou.aliyuncs.com/sycamore/sycamore:house
    
    服务器端拉取镜像
    docker login --username=darksinco registry.cn-hangzhou.aliyuncs.com
    
    docker pull registry.cn-hangzhou.aliyuncs.com/sycamore/sycamore:house

    5.服务器运行项目

    docker run -p 8090:8090 -t registry.cn-hangzhou.aliyuncs.com/sycamore/sycamore:house

    http://47.96.103.135:8090/swagger-ui.html可访问

  • 相关阅读:
    网络编程(1)
    反射,魔法方法,单例模式
    远程的文件传输
    DNS
    windows服务
    outlook邮箱配置
    win7服务器搭建
    windows常用命令
    C盘满了怎么办
    0x80070035找不到网络路径
  • 原文地址:https://www.cnblogs.com/sycamore0802/p/11465926.html
Copyright © 2020-2023  润新知