I am a newbie,I use "java -Djarmode=layertools -jar demo-0.0.1.jar extract" to split my files and wirte a dockerfile to build a image,
example:enter image description here
but,The BOOT-INF/lib of those files are exactly the same, I hope to reduce the size of my docker container,
so I hope those files can share BOOT-INF/lib in the container,can it be done ?
I hope those files can share BOOT-INF/lib in the docker container
Thank!
Related
My Java Springboot cloud run instance finds the files in my resources directory locally when I use
mvn clean spring-boot:run
but when I try to deploy to a cloud run instance it doesn't find the file. What's going on? Google's documentation is completely lacking and the examples don't cover this case. Not sure what's happening.
Obviously, the directory works because I have an application.properties file that's being read.
Folder structure
src
--main
----code
--resources
----application.properties
----kafka.properties
I also ran a func that traces the output of all the files in the dir for default "/" folder when trying to use a file and it just lists
myapp.jar
bin
dev
etc
home
lib
lib64
media
mnt
opt
proc
root
run
sbin
srv
sys
tmp
usr
var
so I think it's pointing to the wrong folder but I'm not sure why or how to change it.
i have the following dockerfile code but the image with over 500mb is way to large. I tried to use multi stage build in order so reduce the size but after that the kubernetes deployment wont work.
FROM openjdk:8
ADD target/name_id.jar name_id.jar
EXPOSE 8080
ENTRYPOINT [ "java","-jar","name_id.jar" ]
With this file it works. Can someone help me?
For the project itself maven and springboot are used. I also have to clean install the jar everytime if i change something in the code.
Can you use openjdk:8-alpine, size of the base image will be 144.9MB.
Use below image for less size
• openjdk:8-jre-alpine: 84 MB
Or you can also try to install alpine os which is 5 MB and openjdk separately and check sizes
Personally, there are two things that come to mind when I think of minimizing the docker image
Base Images
Multistage Builds
Le me try to answer your question
I would used the small jdk image i.e openjdk:8-alpine
I would used this if I wanted to create the jar file inside the Dockerfile AND execute it. In you case, you just want to use an already existing jar file.
Since you already have and want to use the jar file named name_id.jar,
Then you just need the java runtime environment i.e openjdk:8-jre-alpine rather than openjdk:8-alpine
I have a simple Java backend build with Maven. When I create .jar file with mvn clean install, I can run it and everything works fine.
However, when I deploy it to Docker, the server runs, but when I make a GET call, the backend doesn't see static .png file located in src/main/resousces/.
java.io.FileNotFoundException: /src/main/resources/logo.png (No such file or directory)
The image is uploaded to docker with this .gitlab-ci.yml file:
services:
- docker:dind
before_script:
- docker info
maven-build:
stage: build
tags:
- maven3-jdk11
except:
- tags
script:
- mvn deploy -B -U
maven-release:
stage: deploy
tags:
- maven3-jdk11
only:
- tags
script:
- mvn deploy -B -Prelease-profile -Dmaven.javadoc.failOnError=false
(This is my first time working with Maven and Docker, so if the information I provided is not sufficient, please leave a comment.)
Okay, I managed to solve it using java ClassLoader.
Originally, I loaded the .png file like this:
Image logo = new Image(ImageDataFactory.create("src/main/resources/logo.png"));
I changed that to following and now it works like charm:
ClassLoader classLoader = getClass().getClassLoader();
Image logo = new Image(ImageDataFactory.create(classLoader.getResource("logo.png")));
I accepted Eugene's answer to boost his reputation, he moved me in the right direction.
Unpack your jar file and check if .png file in it. If not, you need to package a jar with the resources folder. If yes, so you need to specify the path to file using classpath.
I have deployed my war file on a remote linux server. I run this war using jetty-runner. Its not feasible for me to push this war multiple time. Its size is huge and it takes aprrox 45 min to push a fresh war onto the server. To handle this issue I thought of using the following steps(with commands) :
unzip:Unzip war to its corresponding files/folders : WEB-INF, META-INF, index.jsp.
Updating new class file in WEB-INF.
zip:Repacking these folder into a war again.
But the newly created war does not work. Is there a standard/correct way to pack these files into a war. Also, jar command is not available on the server.
Please suggest.
P.S. Already looked into various SO questions but didn't find any useful solution.
The zip command does not work as expected. The war packed by that command did not work. Instead, we have to use the JAR command.
I was able to generate the war after modifying the contents by using :
jar -cvf webproject.war index.jsp META-INF/ WEB-INF/
Note: If the jar command is not available on the server, specify JAR path using installed java on the server:
PATH_TO_JAVA/bin/jar -cvf webproject.war index.jsp META-INF/ WEB-INF/
here is the structure of my war file.
MyApp.war
WEB-INF
classes/com/info/App.java
classes/application.properties
lib/
META-INF
test
just before deployment of this war to tomcat, Ops team will need to update the application.properties file.
I prefer not to explode. but just to update the war and leave for tomcat to explode during start up
I tried this
jar uvf MyApp.war /var/data/prod/application.properties
After I executed this command, I see a new file being added at root level of MyApp.war. but I want WEB-INF/classes/application.properties to be replaced this one. How can I do it.
I don't believe that it is the good approach anyway, you should externalize your configuration file as it will change from one env to another, so it should not be part of your archive. You should adapt your code to be able to read the configuration of your application from an external folder. Your Ops team will then have the same war to deploy on all env instead of one per env, which is much less error prone.
How about this....
mkdir -p /tmp/MyApp.war/WEB-INF/classes
cp /var/data/prod/application.properties /tmp/MyApp.war/WEB-INF/classes
jar -uvf MyApp.war -C /tmp/MyApp.war WEB-INF
rm -rf /tmp/MyApp.war