Reputation: 31
I'm new to docker and I struggle with "Error: Unable to access jar file target/nbd.jar". My application is a CRUD api for cassandra cluster made with Springboot. I'm trying to execute docker-compose up
. Every cassandra node is running, I only have problem with my API. I think the problem is with the Dockerfile, but I don't know how to solve it myself/ Tried different things but none of them worked.
Here's my Dockerfile:
FROM maven:3.6.0-jdk-11-slim
ARG JAR_FILE
COPY target/${JAR_FILE} target/nbd.jar
ENTRYPOINT ["java","-jar","nbd.jar"]
My filesystem (I cut everything but docker and target files):
├── docker
│ ├── docker-compose.yaml
│ └── Dockerfile
(...)
├── src
│ ├── (...)
├── stop_all.sh
└── target
├── classes
│ (...)
├── generated-sources
│ └── annotations
├── generated-test-sources
│ └── test-annotations
├── nbd.jar
└── test-classes
And my pom.xml:
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.0.16.Final</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>2.1.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-cassandra</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
(...)
</project>
Thanks!
Upvotes: 3
Views: 8441
Reputation: 465
You copy jar file from target
directory on the local computer to the target
directory inside a docker container. But then you didn't specify target
directory in ENTRYPOINT
. Simply put, docker can't find your jar file when it tries to start.
Try this:
FROM maven:3.6.0-jdk-11-slim
ARG JAR_FILE
COPY target/${JAR_FILE} nbd.jar
ENTRYPOINT ["java","-jar","nbd.jar"]
Upvotes: 3