0

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"
Nick
  • 624
  • 8
  • 24
  • Hello Nick, have you tried to build that Dockerfile without the last four run commands? What about the Entrypoint or cmd line? did you add the entire Dockerfile in your post? – Hugo Lesta Jan 06 '21 at 20:29
  • I have not tried to build the file without the last four commands. I've read that its best practice to create a new user so that the image doesn't use the root user. Also I've included everything in my docker file in this post. – Nick Jan 06 '21 at 20:31
  • Thanks for the feedback, I have a little doubt here. Did you test that docker build from a macOS? Make sure you have those settings set properly. System Preferences -> Security & Privacy -> Privacy tab -> Full Disk Access (on the left, somewhere in the list) -> Click on the + -> Docker application – Hugo Lesta Jan 06 '21 at 20:38
  • You are doing `chown user:user -R /app/` then mounting a folder on top of `/app` at run time in your docker compose. If you expect that the `chown` done in your image have an influence on the file mounted after, you are mistaken. – β.εηοιτ.βε Jan 06 '21 at 21:00

3 Answers3

2

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.

Hugo Lesta
  • 721
  • 4
  • 14
2

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.

Nick
  • 624
  • 8
  • 24
  • I don't know anything about docker, but adding a `:` to a list of paths looks like the traditional method of composing PATH lists in *nix land, i.e. `PATH=/usr/local/bin:/usr/bin:/bin:./bin`. Note that I've included `./bin` which would be a relative path compared to the base path of where the program has been started (oftentimes `/home/$USER`. Glad you solved your problem! Good luck to all! – shellter Jan 09 '21 at 23:11
0

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
Ivan Starostin
  • 8,798
  • 5
  • 21
  • 39