How to fix "Permission Denied" error while trying to save and serve files from docker+nginx+uwsgi+flask

How can I grant read/write access to a folder within my docker container to my flask app?

I am new to docker and web servers and don’t really know what I’m doing. I followed the tutorial found here ( https://code.visualstudio.com/docs/python/tutorial-create-containers ).

The name of my directory is “app” instead of “hello_app” and my static folder is called “uploads” instead of “static”. I am not using it as a folder for static files, which could be part of the problem.

The goal is for a user to be able to upload an image file, and then download it again.

Everything works fine if I run my flask app using the flask development server by putting this line in my Dockerfile: CMD [“flask”, “run”, “–host”, “0.0.0.0”]

However if I comment out the flask line so that my app is run through uWSGI I get this error when my flask app tries to save the uploaded image to the uploads directory: “PermissionError: [Errno 13] Permission denied: ‘/app/uploads”

This tells me that there is nothing wrong with my flask app and my problem is some kind of a permissions issue. I don’t know how to resolve this.

I have tried adding lines such as “RUN chmod g+w /app/uploads” and variations of it to my Dockerfile. I have tried putting all of my files in the same parent directory. I have tried re-arranging my directories. I have also tried some of the potential solutions found here to no avail: Django [Errno 13] Permission denied: '/var/www/media/animals/user_uploads'

Dockerfile:

FROM tiangolo/uwsgi-nginx-flask:python3.7

LABEL Name=name-here Version=0.0.1
ENV LISTEN_PORT=5000
EXPOSE 5000

ENV UWSGI_INI uwsgi.ini

ENV STATIC_URL /app/uploads

WORKDIR /app
COPY . /app


# Using pip:
RUN python3 -m pip install -r requirements.txt

#CMD ["flask", "run", "--host", "0.0.0.0"]

uwsgi.ini:

[uwsgi]
module = app.main
callable = app
uid = 1000
master = true
threads = 2
processes = 4

Source: StackOverflow