pythonpipdockerfile

Changing WORKDIR in Dockerfile prevents from using pip install requierments.txt correctly


I have this code:

FROM python:3.10-slim

WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY ./app /app/app

CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]

When I'm remapping my WORKDIR path and so path to copy to: WORKDIR /dev COPY ./app /dev/app

FROM python:3.10-slim

WORKDIR /dev
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY ./app /dev/app

CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]

I'm getting ERROR: Could not open requirements file: [Errno 2] No such file or directory: 'requirements.txt' failed to solve: process "/bin/sh -c pip install --no-cache-dir -r requirements.txt" did not complete successfully: exit code: 1

I expected to see no error when switching paths in both copy and workdir but for some reasons it's not working. I'm wondering if there r any copy things going on with how docker copy everything.

also my working dir is

proj/
│
├── app/
│   ├── some_files
│
├── Dockerfile
└── requirements.txt

Solution

  • /dev is reserved somehow by docker itself. That's why I can't use it as my workdir. I hope it is really so and I'm not misunderstanding something. As mentioned in comments down below, thx to @phd, /dev is a special directory in Unux/Linux