Accessing json inside Docker-conatiner with Rest-call

I have a Docker container running and have mounted my directory to the container. The directory is inside the container and I can access the files if I exec into it. In this container I have java code, in which I am executing a Rest call to get the data and it is not working.

I mounted the directory within my jenkins-script with -v $JENKINS_USER_HOME/test/values:/values

When I am executing my rest calls in java, I am always getting the error, that the json can’t be found. I am trying to access a file called person inside the values folder I already tried the following calls:

  • values/person.json
  • /values/person.json
  • person.json
  • /person.json
  • /values/dir/person.json
  • /dir/person.json
  • /home/docker-user/test/values/dir/person.json

and none of them are working.

I want to have Get- and PostMapping to this json. IS this even possible like this?

Files inside the container for aplpications running inside the container are just regular files. If you can access those files from the command line inside the container, you should be able to do that from the Java app. If you can’t, try to debug it by creating a Java app which lists the files and see what Java can see.

I was finally able to access the files on the docker.

I was using ResourceReader.readFileToString("/values/person.json");

after debugging and trying I used the BufferedReader and with this reader it was working fine

ResourceReader.readFileToString(“values/person.json”);