Issue with Docker Build: "Could not open requirements file: No such file or directory"


I’m encountering a problem with a Docker build process, and I’m seeking assistance to diagnose and resolve the issue.

Problem Description:
I have a Dockerfile and a requirements.txt file in the same directory. However, when I attempt to build the Docker image using the docker build command, I receive the following error:

ERROR [4/4] RUN pip install -r requirements.txt:
Could not open requirements file: [Errno 2] No such file or directory: 'requirements.txt'

I’ve tried various troubleshooting steps, including confirming the directory structure, file permissions, filename case sensitivity, and using the --no-cache option, but the problem persists.

Directory Structure:

  • Dockerfile
  • requirements.txt

Dockerfile Contents:

# Use an official Python runtime as a parent image
FROM python:3.8

# Set the working directory
WORKDIR /template_automating_in_aws

# Copy the current directory contents into the container at /app
COPY . /app

# Install the required packages specified in requirements.txt
RUN pip install -r requirements.txt

# Make port 80 available to the world outside this container

# Define environment variable
ENV KEY password_easy

# Run when the container launches
CMD ["python", ""]

Steps Taken:

  • Checked file permissions for requirements.txt.
  • Confirmed directory structure.
  • Checked for .dockerignore exclusions. (I don´t create ones)
  • Ensured correct context for docker build.
  • Restarted the computer.
  • Tried building with --no-cache.

System Information:

  • OS: Macbook Air 16GB
  • Docker Version: 24.0.6

If anyone has encountered a similar issue or has any insights into what might be causing this error, I would greatly appreciate any help and guidance to resolve it.

Thank you in advance for your assistance.

I’m not sure why you expect it to work or what you meant by checking directory structure, but your workdir is clearly not /app/ where you copied your requirements.txt file. If you want to make sure you always refer to the right file, use full path like

RUN pip install -r /app/requirements.txt

When I said app directory I mean template_automating_in_aws, where my app is stored in local.

Sorry if the comment wasnt clear I just adjusted it. Thank you

I was writing about the facts in your Dockerfile in which you copy files to a folder (/app) but your WORKDIR is another folder (your aws folder) so that’s where pip would look for the requirements.txt but you didn’t copy anything to that.