Docker add warfile to official Tomcat image

流过昼夜 提交于 2019-11-27 01:06:28

问题


I pulled official Docker image for Tomcat by running this command.

docker run -it --rm tomcat:8.0

By using this as base image I need to build new image that contains my war file in the tomcat webapps folder. I created Dockerfile like this.

From tomcat8
ADD warfile /usr/local/tomcat

When I run this Dockerfile by building image I am not able to see Tomcat front page.

Can anybody tell me how to add my warfile to official Tomcat images webapp folder.


回答1:


Reading from the documentation of the repo you would do something like that

FROM tomcat
MAINTAINER xyz

ADD your.war /usr/local/tomcat/webapps/

CMD ["catalina.sh", "run"]

Then build your image with docker build -t yourName <path-to-dockerfile>

And run it with:

docker run --rm -it -p 8080:8080 yourName
  • --rm removes the container as soon as you stop it
  • -p forwards the port to your host (or if you use boot2docker to this IP)
  • -it allows interactive mode, so you see if something get's deployed



回答2:


Building on @daniel's answer, if you want to deploy your WAR to the root of tomcat, I did this:

FROM tomcat:7-jre7
MAINTAINER xyz

RUN ["rm", "-fr", "/usr/local/tomcat/webapps/ROOT"]
COPY ./target/your-webapp-1.0-SNAPSHOT.war /usr/local/tomcat/webapps/ROOT.war

CMD ["catalina.sh", "run"]

It deletes the existing root webapp, copies your WAR to the ROOT.war filename then executes tomcat.




回答3:


How do you check the webapps folder?

The webapps folder is within the docker container. If you want to access your webapps container you could mount a host directory within your container to use it as webapps folder. That way you can access files without accessing docker. Details see here

To access your logs you could do that when you run your container e.g.

docker run -rm -it -p 8080:8080 **IMAGE_NAME** /path/to/tomcat/bin/catalina.sh  && tail -f /path/to/tomcat/logs

or you start your docker container and then do something like:

docker exec -it **CONTAINER_ID** tail -f /path/to/tomcat/logs



回答4:


docker run -it --rm --name MYTOMCAT -p 8080:8080 -v .../wars:/usr/local/tomcat/webapps/ tomcat:8.0

where wars folder contains war to deploy



来源:https://stackoverflow.com/questions/27818856/docker-add-warfile-to-official-tomcat-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!