Search code examples
javadockerdocker-volume

Associate a folder from a container with a folder on Linux where the files are located. Error No such file or directory


in java application, I work with some files and since they can be changed and added, I had to create a separate directory where the files will be located.

in the application i scan the file application.properties . in it I specified a variable and assigned the path to the file home.path=/myapp/resource/fil.xls further work in the application goes with this variable.

i created an image in Dockerfile

FROM openjdk:17-oracle
WORKDIR /myapp
COPY apps-0.0.1-SNAPSHOT.jar /myapp/app.jar
ENTRYPOINT ["java","-jar","app.jar"]

I launch the container

podman run --name apps -p 8080:8080 -d localhost/back-cand -v /home/docker-ad/resourсe:/myapp/resource/ 

/home/docker-ad/resourсe  - this directory points to the folder where the files are stored on linux
/myapp/resource/   - this directory with the folder must be in the container 

I will add files to the "resource" folder and the application in the container should see them and work with them.

an error comes out : java.io.FileNotFoundException: /myapp/resource/fil.xls (No such file or directory)

tell me how to connect them correctly, provide an example


Solution

  • try to create a directory in the dockerfile mkdir /myapp, because when you specify the volume, the directory is not created and therefore the search is carried out in the directory which does not exist