简体   繁体   English

Tomcat Docker容器:作为容器webapp目录挂载的主机webapp目录

[英]Tomcat Docker Container: host webapp directory mounted as container webapp directory

I'm trying to deploy a Java Web application located in my Host OS (Windows 10) and I would like to mount the mentioned webapp as a directory under Tomcat Docker Container (location /usr/local/tomcat/webapps/mywebapp ). 我正在尝试部署位于主机OS(Windows 10)中的Java Web应用程序,并且我想将提到的webapp作为目录安装在Tomcat Docker Container下(位置/usr/local/tomcat/webapps/mywebapp )。

I'm running the following command in the Docker terminal (absolute path for my webapp in Windows). 我在Docker终端(Windows中我的webapp的绝对路径)上运行以下命令。 Note: "mywebapp" host directory already contains the deployed/uncompressed war. 注意:“ mywebapp”主机目录已经包含已部署/未压缩的war。

docker run --name=tomcat_7_0_78 --detach --publish 8080:8080 -v /c/desarrollo/workspace/webMavenTest/target/mywebapp:/usr/local/tomcat/webapps/mywebapp tomcat:7.0.78

I can see that Tomcat starts and the webapps Container folder has several default webapps inside it including the "mywebapp" folder. 我可以看到Tomcat启动,并且webapps容器文件夹中有几个默认的webapp,包括“ mywebapp”文件夹。 The problem is that it is empty so the webapp is not working. 问题是它为空,因此webapp无法正常工作。

I would like to use this to integrate my applications in the Eclipse IDE with Docker and achieve redeploying the application when I make changes through my IDE. 我想用它来将我的应用程序与Docker集成在Eclipse IDE中,并在通过IDE进行更改时实现重新部署该应用程序。

Any insight? 有见识吗?

Thanks in advance. 提前致谢。

If you want to a hot deploy every file changes, it is not possible to do it with a remote application server. 如果要热部署每个文件更改,则无法使用远程应用程序服务器来进行。 The reason is that eclipse does not have control of the tomcat process to do it. 原因是eclipse无法控制tomcat进程来执行此操作。

Now a possible workaround is to generate a webapp that generates a volume to a copy of the deliverable, so that after making a change you can do a build of the application and tomcat install it again. 现在,一种可能的解决方法是生成一个Web应用程序,该Web应用程序生成可交付成果的副本的卷,以便进行更改后,您可以构建应用程序并再次安装tomcat。

It should look like this: 它看起来应该像这样:

docker run --name = tomcat_7_0_78 --detach --publish 8080: 8080 -v /path/to/copy/war/app.war:/usr/local/tomcat/webapps/app.war tomcat: 7.0.78

And in your host you must make a copy of the "war" outside your project to the target of your application. 在主机中,您必须将项目外部的“战争”副本复制到应用程序的目标。 This is necessary because when maven deletes the target folder the docker volume is disattached and does not refresh again. 这是必要的,因为当maven删除目标文件夹时,docker卷将被分离并且不会再次刷新。

To automate the deployment with plugins that perform hook over the save action: 要使用执行挂钩保存操作的插件来自动化部署,请执行以下操作:

How do I start Maven "compile" goal on save in Eclipse? 如何在Eclipse中保存时启动Maven“编译”目标?

I do not recommend it, because you run maven all the time and it consumes a lot of cpu. 我不建议这样做,因为您一直在运行Maven,并且会消耗大量的CPU。 Maybe write a local script to do it. 也许写一个本地脚本来做到这一点。

Thank you for your time and your answer, very helpful, I really appreciate it. 感谢您的时间和回答,非常有帮助,非常感谢。

I expected an easier way to integrate this, but it seems there is no direct solution. 我期望有一个更简单的方法来集成此方法,但是似乎没有直接的解决方案。

By the way, I have found out why the webapp directory was always empty in the Tomcat Docker Container, it seems that my webapp host path (Windows) must be under my user directory, something like this /c/users/username/documents/....../eclipseWorkspace/mywebappProject/target/mywebapp. 顺便说一句,我发现了为什么在Tomcat Docker Container中webapp目录始终为空的原因,看来我的webapp主机路径(Windows)必须位于用户目录下,例如/ c / users / username / documents / ...... / eclipseWorkspace / mywebappProject /目标/ mywebapp。

For the moment I think that I will enable remote debugging so I will have hot code replacement whenever I modify a Java class, and later see what could be done with other types of files. 目前,我认为我将启用远程调试,因此每当我修改Java类时都会进行热代码替换,以后再看看其他类型的文件可以做什么。

About the problem you mention when maven deletes the target folder, I have checked that the webapp is disattached if I run a maven clean from Eclipse (as you said), but if I do a maven install it appears again within the Tomcat Docker Container, so maybe is not that bad. 关于您在maven删除目标文件夹时提到的问题,如果已经从Eclipse运行maven clean(如您所说),我已经检查了webapp是否已断开连接,但是如果执行maven安装,它将再次出现在Tomcat Docker Container中,所以也许还不错。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM