Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access to a folder host via a docker container?

I'm actually stuck with the problem of a shared file.

I want to access my host folders so I did something like this in my Jenkinsfile :

sh "sudo docker run -d -it -p 16000:16000 -v /PATH/TO/MY/HOST/FOLDER/:/var/tmp --name botvolume MY_IMAGE"

And in my scala class I'm trying to get all the folders by using :

val folders: Array[File] = new File("/PATH/TO/MY/HOST/FOLDER/") 
  .listFiles
  .filter(_.isDirectory)

But it's doesn't work, it returns a size equal to 0.

I read the docker volumes documentation

Can someone help me?

like image 820
Myriam K. Avatar asked Oct 28 '25 02:10

Myriam K.


1 Answers

Inside the container the volume path is /var/tmp

Then your code should be :

val folders: Array[File] = new File("/var/tmp/") 
  .listFiles
  .filter(_.isDirectory)

You can find the detail on the Docker volume bind syntax on the link you provided:

-v or --volume: Consists of three fields, separated by colon characters (:). The fields must be in the correct order, and the meaning of each field is not immediately obvious.

  • In the case of bind mounts, the first field is the path to the file or directory on the host machine.
  • The second field is the path where the file or directory will be mounted in the container.
  • The third field is optional, and is a comma-separated list of options
like image 178
Guillaume Barré Avatar answered Oct 30 '25 16:10

Guillaume Barré