Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
550 views
in Technique[技术] by (71.8m points)

django - Permission denied: '/app/manage.py' Docker

I'm having a permissions issue when trying to run my docker-compose command

docker-compose run app sh -c "django-admin.py startproject app ."

ERROR:

PermissionError: [Errno 13] Permission denied: '/app/manage.py'

I've done some research and found a similar issue here: docker-compose , PermissionError: [Errno 13] Permission denied: '/manage.py'

However I think I'm doing something wrong when trying to change permissions in my Dockerfile

Dockerfile:

FROM python:3.8-alpine
MAINTAINER Nick

ENV PYTHONUNBUFFERED 1

COPY ./requirements.txt /requirements.txt
RUN pip install -r /requirements.txt

RUN mkdir /app
WORKDIR /app
COPY ./app /app

RUN adduser -D user
RUN chown user:user -R /app/
RUN chmod +x /app
USER user

I add RUN chown user:user -R /app/ and RUN chmod +x /app

running docker build . works succesfully however I still keep getting permissions issue

docker-compose.yml

version: "3"

services:
    app:
        build:
            context: .
        ports:
            - "8000:8000"
        volumes:
            - ./app /app
        command: >
            sh -c "python manage.py runserver 0.0.0.0:8000"
question from:https://stackoverflow.com/questions/65602867/permission-denied-app-manage-py-docker

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It seems your Django project works well, I've tried to reproduce your error but I couldn't get it.

My directory tree:

.
|____app
| |____app
| | |____asgi.py
| | |______init__.py
| | |____settings.py
| | |____urls.py
| | |____wsgi.py
| |____manage.py
|____requirements.txt
|____Dockerfile
|____docker-compose.yml

requirements.txt

Django==3.1.5

Dockerfile:

FROM python:3.8-alpine

ENV PYTHONUNBUFFERED 1

COPY ./requirements.txt /requirements.txt
RUN pip install -r /requirements.txt

RUN mkdir /app
WORKDIR /app
COPY ./app /app

RUN adduser -D user
RUN chown user:user -R /app/
RUN chmod +x /app
USER user

Docker-compose:

version: "3"

services:
    app:
        build:
            context: .
        ports:
            - "8000:8000"
        volumes:
            - ./app /app
        command: >
            sh -c "python manage.py runserver 0.0.0.0:8000"

My steps:

  1. django-admin startproject app
  2. docker-compose build app
  3. docker-compose up

Output:

Creating django-3-1-5_app_1 ... done
Attaching to django-3-1-5_app_1
app_1  | Watching for file changes with StatReloader
app_1  | Performing system checks...
app_1  |
app_1  | System check identified no issues (0 silenced).
app_1  |
app_1  | You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
app_1  | Run 'python manage.py migrate' to apply them.
app_1  | January 06, 2021 - 21:03:42
app_1  | Django version 3.1.5, using settings 'app.settings'
app_1  | Starting development server at http://0.0.0.0:8000/
app_1  | Quit the server with CONTROL-C.
app_1  | [06/Jan/2021 21:03:52] "GET / HTTP/1.1" 200 16351
app_1  | [06/Jan/2021 21:03:52] "GET /static/admin/css/fonts.css HTTP/1.1" 200 423
app_1  | [06/Jan/2021 21:03:52] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 200 85876
app_1  | [06/Jan/2021 21:03:52] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 200 85692
app_1  | [06/Jan/2021 21:03:52] "GET /static/admin/fonts/Roboto-Bold-webfont.woff HTTP/1.1" 200 86184
app_1  | Not Found: /favicon.ico
app_1  | [06/Jan/2021 21:03:52] "GET /favicon.ico HTTP/1.1" 404 1969
^CGracefully stopping... (press Ctrl+C again to force)
Stopping django-3-1-5_app_1 ... done

Browser:

enter image description here

I'm thinking, you have another kind of perm issue, have you tried to build this image from a MacOS?

Try the following configuration:

System Preferences -> Security & Privacy -> Privacy tab -> Full Disk Access (on the left, somewhere in the list) -> Click on the + -> Docker application

enter image description here

I hope it may help you and other users.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...