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:

Filestructure:

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

Dockerfile:

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

docker-compose.yml:

version: '3'

services:

  django:
    container_name: django_123
    build:
      context: ./..
      dockerfile: ./docker/Dockerfile
    expose:
      - "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