Issue
The issue arises when I attempt to proceed without using volumes; everything works correctly. However, when volumes are included, I get the following error:
django_app | python: can't open file '/app/manage.py': [Errno 2] No such file or directory
docker-compose :
version: '3.8'
services:
app:
build: .
volumes:
- ./django:/app // the problem is here
ports:
- "8000:8000"
image: app:django
container_name: django_app
command: python manage.py runserver 0.0.0.0:8000
dockerfile :
FROM python:3.12.1-slim
ENV PYTHONUNBUFFERED=1
WORKDIR /app
COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt
COPY . .
the commands that i use to build and run :
docker-compose build
docker-compose up
Solution
When I attempt to proceed without using volumes; everything works correctly.
Perfect. Do that.
More specifically, delete this block:
volumes:
- ./django:/app // the problem is here
This hides everything in the /app
directory in the image, and replaces it with whatever happens to be in the django
subdirectory of the directory containing the docker-compose.yml
file. If different hosts have different versions of the application checked out, you'll get inconsistent results – this reintroduces the "works on my machine" problem that Docker frequently tries to avoid.
If the Dockerfile does any sort of rearrangement or manipulation of the source file, the bind mount will also hide this. I've seen Dockerfiles that try to correct DOS line endings or file permissions, for example, and the bind mount will hide those changes.
The more specific disconnect here seems to be that you're COPY . .
the current directory into /app
into the image, but then the bind mount hides that and replaces it with a ./django
subdirectory. Bind-mounting a different subdirectory means that the container filesystem looks totally different from what's in the image. The command:
override tries to run the script that's in ./django/manage.py
on the host system. If the script is actually in the top-level directory, the bind mount hides the copy that's in the image.
Answered By - David Maze
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.