-1

I am struggling with docker and the file system. I would like to write a file in a docker volume from my Java application. The main goal is that another application running on the same machine can read the file.

I read the related question, but I did not find any answer solving this with a java application. Any idea on how to do this?

Paul Fournel
  • 10,807
  • 9
  • 40
  • 68

1 Answers1

1

Building on the answer to your other question:

Example

So you have two docker containers with a need to share a file system? Assuming your java application is containerized, use it to create a persistent data container:

$ docker create -v /data --name mydata mydockerimage

Run your containerized programs using this data container

$ docker run -it --rm --volumes-from mydata mydockerimage create "/data/myfile.csv"
$ docker run -it --rm --volumes-from mydata mydockerimage read   "/data/myfile.csv"

It's possible to pull files out of the data container:

$ docker cp mydata:/data/myfile.csv myfile.csv

Finally you'll want to cleanup the data container eventually

$ docker rm -v mydata

Update

You have not indicated how you're building or using your java program. I have assumed it's an executable jar that can either write or read a CSV file:

java -jar myjar.jar create "/data/myfile.csv"
java -jar myjar.jar read   "/data/myfile.csv"

For an example of how to build such a container see:

Community
  • 1
  • 1
Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185