docker-library/tomcat

Unable to create files from Tomcat's app to binded folder

LordMilutin opened this issue · 3 comments

Hello!

I have a Tomcat9 app that is running in a Docker container. It creates folders and files in "uploads" folder based on issue ID. Everything works great but I am losing those files when taking the container down. So, I decided that it would be best to link a local folder to that uploads folder in a container with these lines in docker-compose:

   volumes:
     - "./data/uploads:/usr/local/tomcat/webapps/uploads"

However, even though I see the folders are being created in uploads (with the owner being root), files are not. They aren't even in the docker container after further inspection.

Did anyone else experience a similar issue?

I have almost the same app and it's working well with this method, the only difference being that it doesn't create folders, just files (with the owner being root, but they're working fine).

What are the permissions on your ./data/uploads and the files in it?

What are the permissions on your ./data/uploads and the files in it?

That folder is initially empty since it will be filled once my app starts creating documents.

It has 775 permissions, and it is owned by my logged-in user which is not root (the same setup I did for the previous app that is working correctly).

Yeah I'm not sure, it definitely seems like a permissions issue or something with your environment. It's also tricky to reproduce as "natively" as possible outside of a custom application for populating that directory with files, since just manually putting files in there doesn't reproduce the issue

$ docker run -d --name tomcat -p 8888:8080 -v "$PWD"/uploads:/usr/local/tomcat/webapps/uploads tomcat:9
90cd7c0bb94adba137bfd94e4ccb6dd080a7e28fe4a1592060c00d63288827eb

$ docker exec -it tomcat bash
root@90cd7c0bb94a:/usr/local/tomcat# mkdir webapps/uploads/testdir
root@90cd7c0bb94a:/usr/local/tomcat# touch webapps/uploads/testdir/file
root@90cd7c0bb94a:/usr/local/tomcat# exit
exit

$ ls -l uploads/testdir/
total 0
-rw-r--r-- 1 root root 0 Nov  9 22:56 file

So there's nothing innately preventing files being replicated in that directory. You could also try asking over at the Docker Community Forums, Docker Community Slack, or Stack Overflow.