Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

python - docker-compose , PermissionError: [Errno 13] Permission denied: '/manage.py'

After doing many research I didn't found any solution worked for me. I am trying to run command in docker-composer to start project with django-admin

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

Every time I am getting the error:

    Traceback (most recent call last):
  File "/usr/local/bin/django-admin", line 10, in <module>
    sys.exit(execute_from_command_line())
  File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 323, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 364, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python3.7/site-packages/django/core/management/commands/startproject.py", line 20, in handle
    super().handle('project', project_name, target, **options)
  File "/usr/local/lib/python3.7/site-packages/django/core/management/templates.py", line 155, in handle
    with open(new_path, 'w', encoding='utf-8') as new_file:
PermissionError: [Errno 13] Permission denied: '/manage.py'

My docker file

FROM python:3.7-alpine
MAINTAINER anubrij chandra

ENV PYTHONUNBUFFERED 1

COPY ./requirements.txt /requirements.txt

RUN pip install -r /requirements.txt

RUN mkdir /app
COPY ./app /app



RUN adduser -D dockuser
USER dockuser

My 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"

I applied solution suggested in but it didn't worked [PermissionError: [Errno 13] Permission denied: '/code/manage.py'

Ubuntu version :

Distributor ID: Ubuntu
Description:    Ubuntu 18.04 LTS
Release:    18.04
Codename:   bionic
See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

ubuntu 21.04

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

I didn't own the unix socket, so I chowned it.

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...