使用jboss或tomcat服务器在docker中运行java应用程序

 一根吃兔子的萝卜 发布于 2022-12-29 14:05

我已经在我的windows机器上安装了docker并按照" https://registry.hub.docker.com/u/dockerfile/java/ "的说明运行java安装映像,它允许我按预期运行java命令.但是,假设我有一个需要在Jboss或tomcat上运行的Java应用程序.如何为此创建映像以及如何添加应用程序war文件以在服务器中部署.因为我对创建docker文件知之甚少.如果你能告诉我们如何做到这一点真的很有帮助,这样我就可以使用docker在Jboss/tomcat服务器的任何地方运行我的应用程序.

1 个回答
  • 像这样创建一个Dockerfile:

    FROM dockerfile/java
    
    # Install Tomcat
    RUN sudo apt-get update && sudo apt-get install tomcat7
    
    # Add your webapp file into your docker image into Tomcat's webapps directory
    # Your webapp file must be at the same location as your Dockerfile
    ADD mywebapp.war /var/lib/tomcat7/webapps/
    
    # Expose TCP port 8080
    EXPOSE 8080
    
    # Start Tomcat server
    # The last line (the CMD command) is used to make a fake always-running
    # command (the tail command); thus, the Docker container will keep running.
    CMD sudo service tomcat7 start && tail -f /var/log/tomcat7/catalina.out
    

    构建图像:

    $ docker build -t tomcat7-test <Dockerfile's path>
    

    然后,运行它:

    $ docker run -d -p 8080:8080 tomcat7-test
    

    2022-12-29 14:08 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有