I've followed these two post 1 & 2 and neither work. I'm currently building my tomcat with the below.
Build File
FROM tomcat:8.0
COPY server/build/libs/server.war /usr/local/tomcat/webapps/server.war
CMD ["catalina.sh", "run"]
Terminal
docker build -t my_server .
docker run -it -rm -p 8080:8080
When I go to http:localhost:8080 I see the manager home page but http:localhost:8080/server or http:localhost:8080/server/webapp/do not show up. My terminal tells me that my war is getting added, but nothing that says it's expanded
INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive /usr/local/tomcat/webapps/server.war has finished in 2,518 ms
For removing the manager app, you need to put the following RUN command before you copy the WAR in DockerFile.
RUN rm -rf /usr/local/tomcat/webapps/*
The above command removes the default apps available in tomcat.
Your application should be available at http:localhost:8080/server/
Related
Iam Trying to Deploy JSF application on Tomcat9 running in docker
this is my docker file
From tomcat:9.0.65-jdk11-corretto-al2
RUN rm -rf /usr/local/tomcat/webapps/*
EXPOSE 8060
COPY ROOT.war /usr/local/tomcat/webapps/
CMD ["catalina.sh","run"]
When i build the docker file The application starts inside Tomcat but it is stuck without errors in logs
Please Help what the problem might be
Thank you in advance .
I am new in Docker, I would like to know how to install Tomcat Container from the command line, also, what are the pre-requisites, do I need to download Java on Fedora 28 first? Or Tomcat already contains a JVM ?
The tomcat/8.5/jre8/Dockerfile image definition starts with
FROM openjdk:8-jre
So it already includes a JDK.
All you need to do is run the default Tomcat server (CMD ["catalina.sh", "run"]):
$ docker run -it --rm tomcat:8.0
You can test it by visiting http://container-ip:8080
See more at hub.docker.com/_/tomcat/.
All you need is to install docker first.
The OP adds:
To be able to connect I had to run below command to get the container ID with
docker ps
docker inspect <containerid> | grep "IPAddress"
I don't know how to deploying the war file into tomcat 7 with the help of docker container.
It is easy in windows OS because we manually paste our project's war file into webapps folder of tomcat, but in case of docker container it is little bit difficult.
I don't know how to change port of tomcat and add role manager in tomcat-users.xml file in docker because of directory structure of docker container. and how to start tomcat using newly change port number in docker.
The easiest way is to use the volume parameter (-v) with docker run to have the webapps directory and tomcat-users.xml file stay on the host filesystem, not on the container one.
For instance, on a Linux host:
create a file named /tmp/tomcat-users.xml with the correct content for your needs;
Then, create an empty directory named /tmp/webapps.
Now, run your container this way:
docker run -it --rm -p 8888:8080 -v /tmp/tomcat-users.xml:/usr/local/tomcat/conf/tomcat-users.xml:ro -v /tmp/webapps:/usr/local/tomcat/webapps:rw tomcat:7
Then, since the container is started in foreground, connect to another shell (another window) and copy your war file into /tmp/webapps.
It will be automatically deployed.
For instance, on a Windows host:
create a file named c:\tmp\tomcat-users.xml with the correct content for your needs;
Then, create an empty directory named c:\tmp\webapps.
Now, run your container this way:
docker run -it --rm -p 8888:8080 -v //c/tmp/tomcat-users.xml:/usr/local/tomcat/conf/tomcat-users.xml:ro -v //c/tmp/webapps:/usr/local/tomcat/webapps:rw tomcat:7
Then copy your war file into c:\tmp\webapps. It will be automatically deployed.
As for March 2021, using a single command line solution on a Windows Docker, try this:
docker run --name YourApp -v "c/WarFiles/YourApp.war:/usr/local/tomcat/webapps/YourApp.war" -it -p 9090:8080 tomcat:7
Then open your app at http://localhost:9090/YourApp
Note "double quote" in volume and c drive with "Linux" slash / in order to make it work.
I want to build and run my Java Maven web app in a docker container. I tried with a following command:
docker run -it --name my_project -v "$PWD":/usr/src/my_project -w /usr/src/my_project maven:3.5.0-jdk-8 mvn clean install tomcat7:run
It correctly copies the resources, run maven clean install (successful build) and run with tomcat7-maven-plugin that is included in my pom.xml.
Everything works fine and logs are really similar to build and run locally on my windows machine:
Unfortunately on a web browser there is information "connection refused".
What could potentially cause the problem?:
- my application is windows specific and cannot run on linux?
- app is fully app and running but something wrong is with proxy configuration or port is not configured?
How can i proceed further - investigate the logs? Try to build on windows docker container?
P.S. I check IP of a container with Kitematic app for windows docker.
Possibly three issues. Once your used -w instead of -v
docker run -it --name my_project -v "$PWD":/usr/src/my_project -w /usr/src/my_project maven:3.5.0-jdk-8 mvn clean install tomcat7:run
Which I assumed was a Typo while posting. Next you didn't publish the port on your machine
docker run -p 9998:9998 -it --name my_project -v "$PWD":/usr/src/my_project -w /usr/src/my_project maven:3.5.0-jdk-8 mvn clean install tomcat7:run
This would map the port 9998 (right side) from your container to the port 9998 on your localhost.
Third and last one, your INFO log says listening on localhost:9998. This is not good. Because that means your war is listening from traffic generated inside the the container only and not from outside the container. You need to configure your war so it listens on all interfaces inside the container and bind should be 0.0.0.0:9998
I have configured Jenkins in Docker container. I am able to take a build. After a build I want to move WAR file into my Tomcat server which is running in host system. I have added copy command in post build task. Jenkins is not able to move the WAR to host system , since it is running in container.
How to move WAR file from container to Host system ?
Host path : /home/test/tomcat/webapps
Jenkins container path: /var/jenkins/workspace/dev/welcome/target/welcome.war
I would create a volumne when starting jenkins with docker and then copy the war file there with a normal shell jenkins command. I usually do
docker run -d -v /var/run/docker.sock:/var/run/docker.sock -p 8080:8080 -p 50000:50000 -v /home/docker:/var/jenkins_home --net="host" --env JAVA_OPS="-Xms1024m -Xmx1024m" --privileged=true axltxl/jenkins-dood
The -v option is to create a volumne, which is a shared folder for container and host. In my case I use that for having the jenkins configuration outside docker container.