Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read local file system with Java from Docker container

Tags:

java

docker

I have a java app running on a docker container on mac osx. I want to access a file on a certain directory within the local file system using Paths.get('/Users/username/folder')

I am getting errors because docker is reading from its vm directory. How will I within a java app access the local file system while running the app in docker?

like image 459
Andre Coetzee Avatar asked Oct 12 '25 08:10

Andre Coetzee


1 Answers

You can share the folder in the host machine with the container:

docker run -v your/host/folder:/your/container/folder ....

And then you can use Paths.get('/your/container/folder')

If you map the host folder in the same folder inside the container then you don't have to take care about it in the java code docker run -v your/folder:/your/folder ..... You also have to keep in mind issues with permissions...

Official documentation

like image 55
debus Avatar answered Oct 14 '25 01:10

debus