Nick
Nick

Reputation: 674

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"

Upvotes: 0

Views: 3629

Answers (3)

Rehamnia Walid
Rehamnia Walid

Reputation: 1

It worked for me by removing : from the volume (docker-compose.yml):

change from:

version: '3.7'

services:
    web:
        build: ./app
        command: python manage.py runserver 0.0.0.0:8000
        volumes:
            - ./app/:/usr/src/app
        ports:
            - 8000:8000
        env_file:
            - ./.env.dev

to :

version: '3.7'
services:
    web:
        build: ./app
        command: python manage.py runserver 0.0.0.0:8000
        volumes:
            - ./app//usr/src/app
        ports:
            - 8000:8000
        env_file:
            - ./.env.dev

Upvotes: 0

Nick
Nick

Reputation: 674

For whatever reason changing my

docker-compose.yml from

version: "3"

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

To

version: "3"

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

I modified - ./app /app to - ./app:/app. It fixed the issue. If anyone has an explanation that would be great.

Thanks for the help.

Upvotes: 2

Hugo Lesta
Hugo Lesta

Reputation: 789

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.

Upvotes: 2

Related Questions