On Windows I get error on docker-compose up, eg:
python: can't open file '/code/manage.py': [Errno 2] No such file or directory
This actually happens on many projects trying to deploy them into Docker, so I don't think it's related to python, django or even path locations - it seems a remote file system mapping problem.
I can fix it by simply moving project to the local disk (not even WSL, just normal Windows folder), not the wifi connected (Linux Western Digital MyCloudX2Ultra) NAS where all project files are currently stored. But this is not viable, as the local disk is small SSD, and not a big code repo - naturally a common setup.
So it seems Windows Docker struggles to mount the volumes when code is on NAS:
Dockerfile:
# Pull base image
FROM python:3.10.4-slim-bullseye
# Set environment variables
ENV PIP_DISABLE_PIP_VERSION_CHECK 1
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# Set work directory
WORKDIR /code
# Install dependencies
COPY ./requirements.txt .
RUN pip install -r requirements.txt
# Copy project
COPY . .
Docker-compose.yml:
version: "3.9"
services:
web:
build: .
ports:
- "8000:8000"
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
There's quite a few posts about this "[Errno 2] No such file or directory" but all seem rabbit holes (I may stand corrected) as I've verified this seems related only to NAS source location, so some kind of mapping and/or permissions problem (no surprise between Windows and Linux).
Am using same folder owner and admin user to run both from NAS and locally, but maybe a problem mapping the NAS path - possibly because it's a Windows mapped drive "N:..." when in reality of course the drive is "\\<local IP>\...". Shouldn't be a problem... but it is somewhere! Maybe it's possible to hard-code the path in the docker files (not ideal of course), but not sure of best way.
volumes:block. You similarly don't need a Composecommand:to override the image'sCMD.