将Java webapp部署到在Docker容器中运行的Tomcat 8 [英] Deploying Java webapp to Tomcat 8 running in Docker container

查看:569
本文介绍了将Java webapp部署到在Docker容器中运行的Tomcat 8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Tomcat和Docker很新,所以我可能在这个问题的某个地方遗漏了一个Tomcat。



我想做的是构建一个Docker容器运行SpringBoot Restful Web服务,只返回一些静态数据。这一切都在OSX上运行,所以我也使用Boot2Docker。



我已经编写了我自己的Dockerfile来构建我的应用程序运行的容器:

  FROM tomcat:8.0.20-jre8 

运行mkdir / usr / local / tomcat / webapps / myapp

COPY /1.0-SNAPSHOT/my-app-1.0-SNAPSHOT.war / usr / local / tomcat / webapps / myapp /

这个Dockerfile工作正常,我可以从创建的图像启动容器。

  docker build -t myapp。 

docker运行-it --rm -p 8888:8080 myapp

该容器正确启动并输出错误,并显示说明我的应用程序部署的消息。

  2015年3月22日23:07 :21.217 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory 
部署Web应用程序目录/ usr / local / tomcat / webapps / myapp

容器也正确地将myapp.war复制到Dockerfile中描述的路径。此外,我可以导航到Tomcat的默认页面,以确认Tomcat正在运行,我也可以点击所有的例子等。



出现这个问题,当我导航到 http://192.168.59.103:8888/myapp/getData 我得到了一个404.我不太清楚为什么。我错过了有关.war部署到Tomcat的内容吗?

解决方案

您尝试将war复制到webapps下面的子目录,这是错误的。
将war文件复制到webapps文件夹中。



删除mkdir命令,并将其替换为:

  COPY /1.0-SNAPSHOT/my-app-1.0-SNAPSHOT.war /usr/local/tomcat/webapps/myapp.war 

Tomcat将提取战争。


I am pretty new to Tomcat and Docker - so I am probably missing a Tomcat fundamental somewhere in this question.

What I am trying to do is build a Docker container that runs a SpringBoot Restful web service that just returns some static data. This is all running on OSX so I am using Boot2Docker as well.

I've written my own Dockerfile to build the container that my app runs in:

FROM tomcat:8.0.20-jre8

RUN mkdir /usr/local/tomcat/webapps/myapp

COPY /1.0-SNAPSHOT/my-app-1.0-SNAPSHOT.war /usr/local/tomcat/webapps/myapp/

This Dockerfile works fine and I am able to start the container from the created image.

docker build -t myapp .

docker run -it --rm -p 8888:8080 myapp

This container starts correctly and outputs no errors and displays the message saying my app was deployed.

22-Mar-2015 23:07:21.217 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory 
Deploying web application directory /usr/local/tomcat/webapps/myapp

The container also correctly has the myapp.war copied to the path described in the Dockerfile. Moreover I am able to navigate to Tomcat default page to confirm that Tomcat is running, I can also hit all the examples, etc.

To the problem, when I navigate to http://192.168.59.103:8888/myapp/getData I get a 404. I can't quite figure out why. Am I missing something regarding a .war deploy to Tomcat?

解决方案

You try to copy war to a subdir below webapps, it's wrong. The war file should be copied simple to the webapps folder.

Remove the mkdir command, and replace the copy like this:

COPY /1.0-SNAPSHOT/my-app-1.0-SNAPSHOT.war /usr/local/tomcat/webapps/myapp.war

Tomcat will extract the war.

这篇关于将Java webapp部署到在Docker容器中运行的Tomcat 8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆