Docker cannot find manage.py or Permission denied on '/manage.py'
python3: can't open file '/app/manage.py': [Errno 2] No such file or directoryShort 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.
Fix it fast
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"2Match what you see, then jump to its fix
- 1
The error path is /manage.py, with nothing before itNo WORKDIR, so the process starts in the root folderFix - 2
ls 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
The build is fine, but at run time /app is empty or holds your host filesA bind mount hides the files the image containsFix
- 1
What does the error look like?
python3: can't open file '/app/manage.py': [Errno 2] No such file or directoryPermissionError: [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' Dockerfile2Fix
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.pyConfirmed by docs.docker.com
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/null2Fix
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.pyConfirmed by docs.docker.com
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 volumes2Fix
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:/app3Verify
The file is visible inside the running container.
docker compose run --rm --no-deps web ls /appConfirmed by docs.docker.com
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
- stegnor.comMy company site: 804 pages from a Python and Jinja generator, with 15 free browser tools.
Related fixes
Servers
pip install confluent-kafka fails because librdkafka/rdkafka.h is missing
pip stops while building confluent-kafka from source
The error means pip is compiling confluent-kafka from source, and the compiler cannot find the librdkafka C headers.
3 causes, each with a fixServers
pip install cryptography tries to compile and fails in a Docker build
fatal error: 'openssl/aes.h' file not found
cryptography ships prebuilt wheels.
3 causes, each with a fixServers
Docker build fails with apk: not found in a Python or Ubuntu image
/bin/sh: 1: apk: not found
apk is the package manager of Alpine Linux only.
2 causes, each with a fixServers
Compose cannot start the service: exec "python manage.py runserver" failed
starting container process caused: exec: "python manage.py runserver
The container runtime was asked to run a program literally named 'python manage.py runserver', including the spaces.
2 causes, each with a fixServers
docker logs prints nothing for a Flask or Python container
the output appears only after the app exits, or in large delayed bursts
docker logs only shows what the process writes to standard output and standard error.
2 causes, each with a fixServers
Docker build or container cannot create a directory: permission denied
PermissionError: [Errno 13] Permission denied: '/app/output.csv'
Once USER switches to a non-root account, every later RUN and the container itself run as that account.
3 causes, each with a fix