Home > Blockchain >  Receiving permission denied error with Docker, nginx, uwsgi setup. I can manually write files inside
Receiving permission denied error with Docker, nginx, uwsgi setup. I can manually write files inside

Time:11-29

I'm trying to setup a flask application to run in production using docker, nginx, and uwsgi.

Docker file:

# syntax=docker/dockerfile:1

FROM python:3.8-slim-buster

WORKDIR /flask_app

RUN apt-get clean \
    && apt-get -y update

RUN apt-get -y install nginx \
    && apt-get -y install python3-dev \
    && apt-get -y install build-essential

EXPOSE 8080
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt --src /usr/local/src

COPY . .

COPY nginx.conf /etc/nginx

RUN chmod  x ./start.sh

CMD ["./start.sh"]

# CMD [ "python3", "-m" , "flask", "--app", "main", "run", "--host=0.0.0.0", "-p", "5001"]

uwsgi.ini

`[uwsgi]
module = main:app
uid = www-data
gid = www-data
master = true
processes = 5

#socket = /tmp/uwsgi.socket
socket = 127.0.0.1:8080
chmod-socket = 666
vacuum = true

die-on-term = true`

nginx.conf

user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
    worker_connections 1024;
    use epoll;
    multi_accept on;
}

http {
    access_log /dev/stdout;
    error_log /dev/stdout;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    index   index.html index.htm;

    # Configuration containing list of application servers
    upstream uwsgicluster {

        server 127.0.0.1:8080;
        # server 127.0.0.1:8081;
        # ..
        # .

    }

    server {
        listen       8888 default_server;
        listen       [::]:8888 default_server;
        server_name  localhost;
        root         /var/www/html;

        location / {
            include uwsgi_params;
            uwsgi_pass uwsgicluster;

            uwsgi_read_timeout 1h;
            uwsgi_send_timeout 1h;
            proxy_send_timeout 1h;
            proxy_read_timeout 1h;

        }
    }
}

The web application runs successfully until I try to upload an image to display. Saving it to an uploads folder under static/uploads returns this error: PermissionError: [Errno 13] Permission denied: 'static/uploads/timyoutube.jpg'

I expect to not receive this error as it works using flask run in development mode.

CodePudding user response:

The issue turned out to be a permissions issue with the user www-data not having write permissions.

I changed the owner of the workdir to www-data and that fixed the issue

RUN chown -R www-data:www-data /flask_app
  • Related