Augusto
Augusto

Reputation: 107

Running container can't find the file that it has created to /home/user/ directory

I hope you are having a great day!

I'm new to docker. I think my problem is related to docker's directory tree

My app writes to a file to /home/user directory and then after some time reads that file again.

I got this error from my app.

[error] a.a.OneForOneStrategy - /home/user/bkjw_eqvfohygvkaxoxc-small.jpg
java.nio.file.NoSuchFileException: /home/user/bkjw_eqvfohygvkaxoxc-small.jpg

My dockerized app is unable to create the file and read. I'm thinking that the Docker considers the directory /home/user/ as a absolute directory of host. I thought that the container would write to /home/user directory within the container's directory tree.

So the question is :

How can I specify the path to write the file inside the containers directory tree?

Upvotes: 3

Views: 2751

Answers (1)

Hazim
Hazim

Reputation: 1451

Your understanding about the directory tree is correct. Application running inside a docker container would write to /home/user/ in the container's directory tree.

Your issue seems to be with permissions, your java application probably doesn't have the rights to write to /home/user/ within the container. Either you should change the ownership/rights of the directory you're wanting to write in, or a simple solution I did in such case was to create the directory I wanted to write in, within the java code.

like:

// Create volume directories explicitly so that they are created with correct owner
Files.createDirectories(Paths.get(dirPath));

You can set dirPath String to something like /home/user/mydir IF your requirement is not to write in /home/user/ specifically.

Upvotes: 3

Related Questions