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

18👍

In your dockerfile, you are pointing to a new user dockuser.

RUN adduser -D dockuser
USER dockuser

Hence your container will start with user dockuser which does not seem to have proper permissions to run /manage.py.

You can either

  • remove the above mentioned lines where you create and point to
    dockuser.

OR

  • provide appropriate permissions to user dockuser using chown and chmod commands in your dockerfile for /manage.py file.

I have answered such similar question here.

73👍

ubuntu 21.04

I got here searching for PermissionError: [Errno 13] Permission denied: so i’ll just leave this here.

note: the below answer doesn’t work for multi user systems … see this answer instead for another possible solution


If you want to set it and forget it for 1 user, your own user … here’s what I have on my dev machine.

I didn’t own the unix socket, so I chowned it. ( this got it working straight away )

sudo chown $(whoami):$(whoami) /var/run/docker.sock

Another, more permanent solution for your dev environment, is to modify the user ownership of the unix socket creation. This will give your user the ownership, so it’ll stick between restarts:

sudo nano /etc/systemd/system/sockets.target.wants/docker.socket

docker.socket:

[Unit]
Description=Docker Socket for the API

[Socket]
ListenStream=/var/run/docker.sock
SocketMode=0660
SocketUser=YOUR_USERNAME_HERE
SocketGroup=docker

[Install]
WantedBy=sockets.target

Again another less hacky solution: https://stackoverflow.com/a/70124863/2026508

NOTE for WSL ( NevilleLusimba )

might also want to change directory/app ownership to docker

$ sudo chgrp -R docker /path/to/directory 

and give read and write access to docker

$sudo chmod -R g+rw /path/to/directory 

Worked for me on Ubuntu 22.04 LTS via WSL

13👍

I had the same issue and solved it by adding my user to the docker group:

$ sudo usermod -aG docker $(whoami)

6👍

add this to your Dockerfile after RUN adduser -D dockuser:

RUN chown dockuser:dockuser -R /app/

and why you COPYthe files if you already mount them ?

if you want to keep the mount , you need to add rw persmission on the folder on the HOST system not on the Container

👤LinPy

4👍

If you’re on mac this might work for you.

After 4 days of troubleshooting this error (and other strange errors) I found out that I needed to fix dockers permissions in my file system. To do this go to:

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

Terribly frustrating problem to debug, hope it helps.

1👍

The Dockerfile that I was using was in the shared directory of my virtual machine (VirtualBox). Therefore, my issue was related to the default permission of this directory (UID=root, GID=vboxdf). I had to change it to my current user to properly run my container.

See https://superuser.com/a/640028/1655184 for a description on how to change the owner.

👤Ling

0👍

For me it was a WSL2 / Docker-Desktop setup issue on Windows.

What was missing was to explicitly enable the WSL distro: Docker Desktp Settings > Resources > WSL Integration > enable your distro

Then re-open WSL shell.

Before I could not even do docker run hello-world but also had a very similar error message as the OP when running docker-compose.

👤Tom

0👍

adding path to app like ‘/home/user/app:/app’ in docker-compose instead of just ‘.:/app’ resolved my problem

0👍

For ubuntu, just add sudo to your command and run as root to get the permissions.

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

0👍

I experienced similar issue, the problem was I running docker-desktop. The solution was to exit docker-desktop.
Os: Ubuntu 20.04LTS

rebuild and re-run command after exiting.

Leave a comment