[Answered ]-Getting Permission denied: '/vol/web/media' when trying to create file in my django application

1👍

When you mount volumes: into a container, the content of the host directory or named volume completely hides what was in the image before.

In your case, you’re mounting ./data/web over /vol/web in the image. That means that the mkdir /vol/web/media in the Dockerfile gets hidden: whether or not there is a media directory, and which user owns it, completely depends on the contents of the ./data/web directory on the host.

If you can delete these volumes:, that’s the best solution. For example, you do not need a volume mount hiding the image’s /electron directory since that code is already COPYed into the image.

Otherwise you need to make sure the directory exists on the host

mkdir ./data/web/static ./data/web/media

To make the directory writable from inside the container you need to figure out what numeric user ID owns the directory. Usually it is your current user, and id -u will tell you its numeric uid. In your Compose file, you need to set user: to that numeric uid. You do not specifically need to "create the user" and it’s not a good practice to embed the uid in the Dockerfile.

user: '1000'

Leave a comment