Docker: Cannot COPY from parent directory while building the image [duplicate]

I am trying to use docker-compose up -d for deploying my django application. The problem is that my Dockerfile and docker-compose.yml are in one directory, but need access to a requirements.txt from the parent directory.

Minimal Example:


requirements.txt (file)  
docker (directory)  
  docker/Dockerfile (file)  
  docker/docker-compose.yml (file)


FROM python:3.10-slim
COPY ./../requirements.txt /requirements.txt


version: '3'


    container_name: django_123
      context: ./..
      dockerfile: ./docker/Dockerfile
      - "8000"

The setup works on Docker Desktop 4 on Windows 10, but not on Ubuntu 22.
I get the error:

Step 1/2 : COPY ./../requirements.txt /requirements.txt
COPY failed: forbidden path outside the build context: ../requirements.txt ()
ERROR: Service 'django' failed to build : Build failed

I already read that I should build the image from the parent directory, but I get the same error message if I use docker build -f ../Dockerfile ..

What could be the problem? And why does it work on Windows and not on Ubuntu?

Back to Top