Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

Docker cannot find manage.py or Permission denied on '/manage.py'

Errorpython3: can't open file '/app/manage.py': [Errno 2] No such file or directory

Short answer

The container is looking for manage.py in a directory where the file is not. Without WORKDIR the process starts in /, a COPY may have put the project somewhere else, and a bind mount in Compose can hide the folder you copied. Look inside the running container to see where the files are.

  • Applies to Docker Engine 27, Docker Compose v2, Python 3.12, Django 5.2
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    List the folder in a throwaway container from the same image and compose file to see where the files really are.

    docker compose run --rm --no-deps web sh -c "pwd && ls -la"
  2. 2Match what you see, then jump to its fix

    1. 1The error path is /manage.py, with nothing before itNo WORKDIR, so the process starts in the root folderFix
    2. 2ls shows the files in a sub-folder, such as /app/src/manage.pyCOPY put the project in a different place than the command expectsFix
    3. 3The build is fine, but at run time /app is empty or holds your host filesA bind mount hides the files the image containsFix

What does the error look like?

  • python3: can't open file '/app/manage.py': [Errno 2] No such file or directory
  • PermissionError: [Errno 13] Permission denied: '/manage.py'

Cause 1 of 3

No WORKDIR, so the process starts in the root folder

1Check

The Dockerfile reference says the default working directory is /. A command like python manage.py then looks for /manage.py. Base images may set another directory, so set it yourself.

grep -nE 'WORKDIR|COPY|CMD' Dockerfile

2Fix

Set WORKDIR before the COPY and the command, so both use the same folder.

WORKDIR /app
COPY . /app
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]

3Verify

Rebuild and run; the container shows manage.py in the working directory.

docker compose build web
docker compose run --rm --no-deps web ls manage.py

Confirmed by docs.docker.com

Did this fix it?

Cause 2 of 3

COPY put the project in a different place than the command expects

1Check

A COPY destination that does not start with / is relative to the working directory, and when you copy a directory only its contents are copied. The build context matters too: files outside it are not available.

docker compose run --rm --no-deps web find / -name manage.py -not -path '*/site-packages/*' 2>/dev/null

2Fix

Make the COPY source and destination match your layout, or point the command at the real path.

# project files live in ./src on the host
COPY src/ /app/

3Verify

Rebuild and check the file is at the expected path.

docker compose build web
docker compose run --rm --no-deps web ls /app/manage.py

Confirmed by docs.docker.com

Did this fix it?

Cause 3 of 3

A bind mount hides the files the image contains

1Check

The Docker docs say that when a bind mount covers a non-empty folder in the container, the files already there are obscured. A volumes entry such as .:/code or ./backend:/app replaces what you copied.

docker compose config | grep -A3 volumes

2Fix

Make the mount path the same as the WORKDIR and the host folder the one that holds manage.py, or remove the mount in production.

services:
  web:
    working_dir: /app
    volumes:
      - ./backend:/app

3Verify

The file is visible inside the running container.

docker compose run --rm --no-deps web ls /app

Confirmed by docs.docker.com

Did this fix it?

How do I stop it coming back?

  • Set WORKDIR explicitly in every Dockerfile.
  • Use one path for the COPY target, the Compose mount, working_dir and the command.
  • Run a quick ls inside the built image whenever you change the project layout.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.