0

I am new to Docker. I have a simple Java application runs in docker. It will return an error says 4: java.io.FileNotFoundException:(No such file or directory) when the application tries to locate a file with the host path /mnt/share/abc.json.

Actually the file is exist on the location. The application help to upload files to FTP server and the file abc.json is an example of dynamic files.

Please advise how the application can locate host files in container! Thanks a lot.

Docker file as bellow

#
# Build stage
#
FROM maven:3.6.3-jdk-8 AS build
WORKDIR /home
COPY pom.xml .
RUN mvn dependency:go-offline

COPY src /home/src
RUN mvn -f /home/pom.xml clean package

#
# Package stage
#
FROM openjdk:8-jdk-alpine
COPY --from=build /home/target/*.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","/app.jar"]
KCHC
  • 3
  • 2

2 Answers2

0

The /mnt/share/abc.json is your system is not same as /mnt/share/abc.json in Docker.
You need to copy the file to the desired location using the COPY command. Namely,

COPY <file> <destination>

For more information docker add and copy commands

kesarling He-Him
  • 1,944
  • 3
  • 14
  • 39
  • I used the run command with -v /mnt/share:${PWD}/share. But it fails to locate the file from ./share/abc.json in Java program. – KCHC Sep 18 '20 at 04:36
0

Try adding the abc.json file to where your Dockerfile is located. And then the command would simply be:

COPY abc.json /myimagedir/

Note, /myimagedir has to exist in the image prior to the COPY in order for the COPY to be successful. If it doesn't exist in your image already, you could create it doing something like this:

RUN mkdir /myimagedir

sfb103
  • 264
  • 1
  • 7