Move file from Docker container to Host system in Jenkins - java

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.

Related

Unable to create log folder inside Wildfly server bin folder from docker container

I am running a Java application inside wildfly docker container. While starting the server, we create application log4j folders inside bin folder of wildfly (/opt/wildfly/bin).
I am getting exception: Unable to create file AppLog/AppLog.log java.io.IOException: Could not create directory /AppLog
Command to run docker container: docker run --name app_container --env-file=env-file -p 8080:8080 -p 9990:9990 -it app-resources /opt/wildfly/bin/standalone.sh
Use WORKDIR to set path that user have permission to write on container. For example: /tmp or /path/user/have/permission/to/write

Can we run an executable jar file inside an already running Kubernetes pod?

I need to execute a diagnostic program written for my application. The application is running/deployed in a Kubernetes pod. I want to copy a diagnostic executable jar file inside the Kubernetes pod and execute it without stopping the pod. How can this be achieved ? Is there a specific way to run the executable jar using the Kubernetes pod environment in place ?
You can try the kubectl cp command:
From the docs:
Copy /tmp/foo_dir local directory to /tmp/bar_dir in a remote pod in
the default namespace
kubectl cp /tmp/foo_dir <some-pod>:/tmp/bar_dir
Copy /tmp/foo local file to /tmp/bar in a remote pod in a specific
container
kubectl cp /tmp/foo <some-pod>:/tmp/bar -c <specific-container>
Copy /tmp/foo local file to /tmp/bar in a remote pod in namespace
kubectl cp /tmp/foo <some-namespace>/<some-pod>:/tmp/bar
Copy /tmp/foo from a remote pod to /tmp/bar locally
kubectl cp <some-namespace>/<some-pod>:/tmp/foo /tmp/bar
Once the executable is added inside the container, you can exec into the pod and execute the file manually.
To open up interactive bash terminal
kubectl exec <pod name> -n <namespace> -c <container name> -it bash
After this, find your executable jar and run it. once completed, exit the terminal.
You can run it directly.
kubectl exec <podname> -n <namespace> -c <container name> -- < command to run your jar >
check this official k8s page https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#exec

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

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