Deploy War on Tomcat Running in Docker - java

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 .

Related

Docker for an Angular-Java app : ports not exposed properly

I am trying to dockerize a full-stack Java(Springboot)-Angular app. The Angular app is embedded in the application and makes REST calls to the Java app as GET localhost:8080/getSomeInfo. My Dockerfile is as
FROM maven:3.6.3-openjdk-8 AS build
COPY src /home/app/src
COPY pom.xml /home/app
RUN mvn -f /home/app/pom.xml clean package
FROM openjdk:8-jdk-alpine
COPY --from=build /home/app/target/*.jar /usr/local/lib/app.jar
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} /usr/local/lib/app.jar
ENTRYPOINT ["java","-jar","/usr/local/lib/app.jar"]
FROM node:12.2.0
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY src/main/web/package.json /app/package.json
RUN npm install
RUN npm install -g #angular/cli#10.1.2
COPY src/main/web /app
CMD ng serve --host 0.0.0.0
I build it as
docker build -t springio/myapp .
I need to expose both the angular port and the java port, so I run it as
docker run -p 9898:4200 -p 8080:8080 -t springio/myapp
I am able to bring up the web page, but it cannot reach out to the Java server (can't connect to 8080). How can this be fixed please?
I have tried putting 'EXPOSE 8080' in the dockerfile, but that did not work
You should not put 2 applications in the same container. Although you can, it is considered a bad practise and it defeats the purpose of using containers.
I suggest having 2 Dockerfile: one for the back-end (java app) and one for the front-end (Angular app). Build each of them separately and start them independently.
For your specific problem I don't think the port is the problem, but is the Java app that is not even starting (it is actually not even present in the final image). Splitting the Dockerfile and starting the apps separately will fix your issue.
EXPOSE doesn't actually do anything. It is there to inform users of the Dockerfile which ports the application is listening on, so that they know which ports to map on the host.

how to deploy war file in tomcat 7 of docker container

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.

Cannot see Java Maven Tomcat-plugin web application in web browser

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

Move file from Docker container to Host system in Jenkins

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.

Run war with tomcat in docker

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/

Categories