简体   繁体   中英

How does war file creates directory inside tomcat on docker container

I´m trying to deploy a java api which is basically with a .war fie inside /tomcat/webapps/ directory inside a docker container. I was able to copy the .war file from Artifactory in which is located. So now The tomcat structure inside the docker container is: tomcat/webapps/api.war
Thing is that that after I copy the WAR file over there, I don´t know how is it that java and tomcat works so that the WAr file creates the directory structure of the api with the META-INF , WEB-INF directories under api directory. How is it that the api.war creates the api directory? I thought that it was after starting catlina.sh but apparently is not. This is the part of the dockerfile that I have at the end of the dockerfile (the previuos part is not important since is the tomcat official dockerfile building the image):

RUN curl -u user:pass -O "http://artifactory.xxx.com:443/artifactory/xx-api/xxapi.war"
RUN mv /usr/local/tomcat/xxapi.war /usr/local/tomcat/webapps/ 
RUN rm -rf /usr/local/tomcat/webapps/docs && rm -rf /usr/local/tomcat/webapps/examples \
&& rm -rf /usr/local/tomcat/webapps/host-manager $$ rm -rf /usr/local/tomcat/webapps/manager
RUN ls -la /usr/local/tomcat/webapps/
EXPOSE 8080
CMD ["catalina.sh", "run"]

This works perfectly and the war is copied under the tomcat directory and catalina.sh runs scuccessfully. I need to know how is it that the war creates the directory structure after all this. right now I only have the war file.

thank you!!

在此处输入图片说明

在此处输入图片说明

08-Aug-2018 16:26:51.927 SEVERE [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Error deploying web application archive [/usr/local/tomcat/webapps/gp_searchapi.war] java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/gp_searchapi]] at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:758) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734) at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:985) at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1857) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149 ) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748)

By default tomcat will unpack the war file to deploy it, when you start the server.

From the looks of it, you only built your docker image and you are executing RUN ls -la /usr/local/tomcat/webapps/ inside the image build.

So, when you start your recently built image, tomcat will start (because you defined the default CMD to exec catalina.sh run ).

You can start your new image with the docker run command:

docker run -it --rm -p 8080:8080 <image_name>:<image_version>

You can check your tomcat logs with

docker logs container_name

Also note that you don't need to build an image with tomcat, you can use as your base image an official image from the docker hub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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