3

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?

Augusto
  • 107
  • 10
  • 1
    Can you share your Dockerfile and the docker build logs, so that I can find out where is the issue? – fly2matrix Apr 17 '18 at 04:18
  • 1
    Since you are new to Docker, you might be using `docker run` not properly, like this guy here: [I lose my data when the container exits](https://stackoverflow.com/questions/19585028/i-lose-my-data-when-the-container-exits) – tgogos Apr 17 '18 at 06:39
  • 1
    How you are copying the file. Share your docker, then simple to answer. – Jinna Balu Apr 17 '18 at 07:11

1 Answers1

3

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.

Hazim
  • 1,405
  • 1
  • 11
  • 24
  • As long as container is running, I should be able to access by console this created directory right? Could you tell me where it is located? The files of containers seems to be reside in `/var/lib/docker/overlay2/`, is it correct? – Augusto Apr 17 '18 at 15:49