• java 部署到Linux


    打包

    Maven -- Lifecycle -- clean -- [双击执行]
    Maven -- Lifecycle -- package -- [双击执行]

    Dockerfile

    
    FROM openjdk:8-jdk-alpine
    VOLUME /tmp
    ADD Spring-Boot-Redis-Mybatis-Plus-0.0.1-SNAPSHOT.jar app.jar
    ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
    
    

    其中第3行,"Spring-Boot-Redis-Mybatis-Plus-0.0.1-SNAPSHOT.jar"
    根据你自己的应用名称修改 ~~~

    将打包的jar文件和Dockerfile复制到Linux服务器中

    [
    "Spring-Boot-Redis-Mybatis-Plus-0.0.1-SNAPSHOT.jar",
    "Dockerfile"
    ]
    我是将这两个文件放到一个文件夹"jrm"下了

    
    $ ls /root/release/jrm/
    Dockerfile  Spring-Boot-Redis-Mybatis-Plus-0.0.1-SNAPSHOT.jar
    
    

    docker build

    
     $ cd /root/release/jrm/
    
    $  docker build -t jrm .
    
    Step 1/4 : FROM openjdk:8-jdk-alpine
     ---> a3562aa0b991
    Step 2/4 : VOLUME /tmp
     ---> Using cache
     ---> 6f18f2cb03cd
    Step 3/4 : ADD Spring-Boot-Redis-Mybatis-Plus-0.0.1-SNAPSHOT.jar app.jar
     ---> e81334bc500c
    Step 4/4 : ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
     ---> Running in 77c5661555be
    Removing intermediate container 77c5661555be
     ---> 7069424d6f1c
    Successfully built 1111424d2222
    Successfully tagged jrm:latest
    

    docker run

    
    docker run -itd --name=jrm -p 8060:8060 -v /etc/localtime:/etc/localtime -v /etc/timezone:/etc/timezone jrm
    
    

    到这里如果么有出意外的话就已经部署完成了 ---

    附加 - 查看日志(如果你应用中有日志)

    #进入容器
    $ docker exec -it jrm /bin/sh
    
    #查看文件列表
    / # ls
    app.jar  bin      dev      etc      home     lib      logs     media    mnt      opt      proc     root     run      sbin     srv      sys      tmp      usr      var
    #查看log日志
    
    / # cat /logs/info/spring.log
    2021-07-26 02:44:58.506  INFO 1 --- [main] .r.SpringBootRedisMybatisPlusApplication : Starting SpringBootRedisMybatisPlusApplication v0.0.1-SNAPSHOT using Java 1.8.0_212 on e7515a9700ed with PID 1 (/app.jar started by root in /)
    2021-07-26 02:44:58.508  INFO 1 --- [main] .r.SpringBootRedisMybatisPlusApplication : The following profiles are active: pre
    2021-07-26 02:45:00.294  ...
    
    

    结尾

    本来没有想直接上docker,而是想原始的步骤来将Java部署到Linux上,
    但是看了下原始方法还需要安装Tomcat ---
    还是想直接docker部署吧 ---

  • 相关阅读:
    lower_bound/upper_bound example
    Counter Mode ( CTR )
    85. Maximal Rectangle
    for_each(c++11)
    Lowest Common Ancestor in a Binary Tree
    python--基础学习(五)参数位置传递、关键字传递、包裹传递及解包裹(*args与**kwargs)
    Python的方法解析顺序(MRO)
    pycharm配置总结
    Python中内置数据类型list,tuple,dict,set的区别和用法
    进程号查找
  • 原文地址:https://www.cnblogs.com/love-zf/p/15073534.html
Copyright © 2020-2023  润新知