How can I copy the jar file without specifying the version in the copy command?
Below is the original command
COPY web-app/target/web-app-0.0.1-SNAPSHOT-exec.jar /web-service.jar
Thank you
I use that docker file in my spring projects: with a docker compose up command it runs.
FROM openjdk:8
ADD dockerspringboot.jar dockerspringboot.jar
EXPOSE 8094
ENTRYPOINT ["java", "-jar", "dockerspringboot.jar"]
Related
as far as I know I only got this answer for my query, but unfortunately I do not have docker-compose.yml I am just trying with plain Dockerfile below is my dockerFile.
FROM openjdk:8-jre-alpine
VOLUME /tmp
ARG JAR_FILE
COPY ${JAR_FILE} ebiPorjectJava.jar
ENTRYPOINT ["java","-jar","/ebiProjectJava.jar"]
but build is getting successful, by below command.
docker build -t ebiproject .
but when I am trying to run the docker it says unable to access jar file
docker run -p 3000:3000 ebiproejct
but it says unable to access jar
I am running docker on windows and I have spring boot application to run
I updated with below one:
FROM openjdk:8-jre-alpine
VOLUME /tmp
ARG JAR_FILE
COPY ${JAR_FILE} /ebiProjectJava.jar
ENTRYPOINT ["java","-jar","/ebiProjectJava.jar"]
but now I am getting corrupted error:
ARG JAR_FILE
expects you to pass the path of the jar_file as docker run argument
Otherwise nothing will be copied to the place, thus java jar won't be able to run the jar.
Check this out: https://vsupalov.com/docker-env-vars/
In this situation you can go in your container with this command:
docker run --rm -it <container_name> <image_name> <command>
you can use bash, ash or sh as
and after entering the container, you can check, run, or any tests in that.
I'm beginner with Docker, and I'm trying to build an image in two stages.
The first docker-file is uploaded to docker-hub and has the following structure:
FROM openjdk:8-jdk-alpine
ONBUILD COPY app.jar /app.jar
CMD ["java", "-jar", "/app.jar"]
The second dockerfile:
FROM gradle:4.7.0-jdk8-alpine AS build
COPY --chown=gradle:gradle . /home/gradle/src
WORKDIR /home/gradle/src
RUN ./gradlew build
FROM <repo>/<first_docker_file>:1.0
COPY --from=build /home/gradle/src/build/libs/*.jar /app.jar
So I need to build my project -> generate jar file -> copy it to the root directory of the second docker stage of the second docker file.
I need to copy generated jar-file from the first stage to the root directory of the second stage, cause "ONBUILD COPY app.jar /app.jar" is triggered and is waiting for app.jar file in the root directory. The code I have provided in the second file does not work. I also can't change the code of the first docker-file. Do you have any ideas, how can I make it work and what should I change in the second docker file ?
From the ONBUILD reference i understand that the ONBUILD commands are inserted directly after the FROM command when inheriting from it.
As i understand it this means your app.jar needs to exist when the FROM command is issued, i.e. your effective Dockerfile would look like
FROM <repo>/<first_docker_file>:1.0
COPY app.jar /app.jar
COPY --from=build /home/gradle/src/build/libs/*.jar /app.jar
[...]
which obviously wouldn't work.
It seems like your first dockerfile is not meant to be used in a staged build, you need to get the app.jar in the working directory when issuing the build on the first dockerfile, i.e. by compiling inside a container and copying out your app.jar to your first dockerfile location and then build it.
I have a spring boot application which contains a Main Class. I have Docker File as below:
FROM docker.io/openjdk:11-jre-slim
EXPOSE 8082
EXPOSE 8443
ADD target/base-application.jar app.jar
ENV JAVA_OPTS=""
ENTRYPOINT exec java $JAVA_OPTS -Dspring.profiles.active=prod -jar /app.jar
I am creating a Docker image by using this Docker file. Let's consider that this docker file is Docker1.
I have another Spring Boot application (which doesn't have a Main class) with Docker file as below:
FROM Docker1:0.0.1
EXPOSE 8443
ADD target/child-application.jar child-application.jar
ENV JAVA_OPTS=""
ENTRYPOINT exec java $JAVA_OPTS -Dspring.profiles.active=dev -jar /app.jar
I am using Docker1 as a base image for the docker image of 2nd application. I am running the Main class of Docker1 by running 2nd Docker image. Now there are 2 jar files of another spring boot projects(messagepack1.jar & messagepack2.jar). I want to load these jars in the 2nd docker image. I am trying something like this:
FROM Docker1:0.0.1
EXPOSE 8443
COPY src/main/resources/message-packs/messagepack1.jar m1.jar
COPY src/main/resources/message-packs/messagepack2.jar m2.jar
ADD target/child-application.jar child-application.jar
ENV JAVA_OPTS=""
ENTRYPOINT exec java $JAVA_OPTS -Dspring.profiles.active=dev -jar /app.jar
But it is not loading the jars when I am running the 2nd Docker image. Can you please help me out?
Finally, I could find the solution to this problem:
ADD /src/main/resources/message-packs /external-jars
ENTRYPOINT exec java -cp app.jar -Dloader.path=external-jars/ -Dloader.main=com.example.MainClass org.springframework.boot.loader.PropertiesLauncher
Here, I am adding the External Jars from src/main/resources/message-packs directory to the "external-jars" folder of the Docker Image. Then I am loading these jars to the Classpath of my application by using "java -cp" command.
I want to start my fat JAR inside a Docker container
Docker file
FROM java:8-jre
COPY config.yml /opt/hello/
COPY build/libs/Dockerwizard.jar /opt/hello/
EXPOSE 80
WORKDIR /opt/hello
CMD ["java", "-Xms128m", "-Xmx1500m", "-Dfile.encoding=UTF-8", "-jar", "Dockerwizard.jar", "server", "config.yml"]
Everytime I run
docker build --tag=myapp .
and
docker run -p 18080:8080 -t -i myapp
I get the message
Error: Unable to access jarfile Dockerwizard.jar
How can I resolve this?
It says:
COPY build/libs/Dockerwizard.jar /opt/hello/
...WORKDIR /opt/chat
So you are putting the Jar into /opt/hello, but then you want to run it from /opt/chat.
Maybe you want to look into using consistent path information. Beyond that, when you are not using the -cp option of java, you always have the issue that your CLASSPATH might be incomplete. So try adding -cp . for example.
Try changing the WORKDIR in your Dockerfile
WORKDIR /opt/chat is incorrect
It should be /opt/hello
Update
you have updated the question and renamed /chat to /hello everywhere - so you have made a correction to your error/ mistake
I am trying to dockerize a service that requires mmdb files (maxmind db file format) in a particular location /opt/my-service/db
Locally I am able to run the service if I set up my system by copying required mmdb files to the "/opt/my-service/db" folder.
What should I do for the docker? I tried copying the files by creating same file location in the dockerfile ( NOT working) :
FROM tomcat:8-jre8
EXPOSE 8080
COPY ./my-service/target/my-service-1.0-SNAPSHOT.war /usr/local/tomcat/webapps
cmd mkdir -p /opt/my-service/db
copy ./my-service/src/test/resources/* /opt/ipgeo/db/
CMD ["catalina.sh", "run"]
Is this how it should be done?
OR a container should be created? If yes, how?
cmd mkdir will not be run to build the Dockerfile.
So, replace your Dockerfile by this one:
FROM tomcat:8-jre8
EXPOSE 8080
COPY ./my-service/target/my-service-1.0-SNAPSHOT.war /usr/local/tomcat/webapps
RUN mkdir -p /opt/my-service/db
COPY ./my-service/src/test/resources/* /opt/ipgeo/db/
CMD ["catalina.sh", "run"]
Moreover, are you sure that /opt/my-service/db and /opt/ipgeo/db should not be the same string, in this Dockerfile?
If so, the correct Dockerfile should be:
FROM tomcat:8-jre8
EXPOSE 8080
COPY ./my-service/target/my-service-1.0-SNAPSHOT.war /usr/local/tomcat/webapps
RUN mkdir -p /opt/my-service/db
COPY ./my-service/src/test/resources/* /opt/my-server/db/
CMD ["catalina.sh", "run"]