skip to Main Content

I made sure that the Dockerfile is named correctly and placed in the right folder, but when I try to build an image it is throwing me to an error "ERROR: failed to solve: failed to read dockerfile: open /var/lib/docker/tmp/buildkit-mount636325941/Dockerfile: no such file or directory". Here is my Dockerfile content, I have both the requirements.txt and training_model.py in the same src folder. :

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

# Set environment variables for AWS credentials (replace with your credentials)
ENV MINIO_ACCESS_KEY_ID=your_access_key
ENV MINIO_SECRET_ACCESS_KEY=your_secret_key
ENV MINIO_ENDPOINT=your_minio_endpoint
ENV MINIO_BUCKET_NAME=your_bucket_name

# Set the working directory in the container
WORKDIR /app

# Copy the requirements file into the container
COPY requirements.txt .

# Install any needed packages specified in requirements.txt
RUN pip install -r requirements.txt

# Copy the rest of the application code into the container
COPY . .

# Command to run the training and model publishing script
CMD ["python", "training_model.py"]

Here is the ls and dir:

PS C:UsersmrstaOneDriveDesktopProjectMLsrc> ls


    Directory: C:UsersmrstaOneDriveDesktopProjectMLsrc


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----         12/9/2023   3:19 PM            704 Dockerfile.txt
-a----         12/9/2023   3:11 PM             61 requirements.txt
-a----         12/9/2023   3:55 PM           3736 training_model.py


PS C:UsersmrstaOneDriveDesktopProjectMLsrc> dir


    Directory: C:UsersmrstaOneDriveDesktopProjectMLsrc


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----         12/9/2023   3:19 PM            704 Dockerfile.txt
-a----         12/9/2023   3:11 PM             61 requirements.txt
-a----         12/9/2023   3:55 PM           3736 training_model.py

enter image description here

enter image description here

2

Answers


  1. If the Dockerfile is in the working directory of your shell then no need to pass the file as an argument since the docker build command will automatically look for a file named Dockerfile in the current working directory.

    Same thing with the context directory, you could simply replace it with . rather that C:Users...

    Therefore a shorter command would look like docker build -t model-training-image:1.0 . (don’t forget the dot at the end).

    Try using the above command first. If it still doesn’t work, then there is indeed a typo in your file, or it doesn’t exist in the current working directory.

    EDIT : Just saw that you added screenshots of ls. You have the .txt extension. Remove it

    Login or Signup to reply.
  2. Your Dockerfile is named Dockerfile.txt. The file should just be Dockerfile with no extension. Most likely your IDE or file manager is hiding extensions from you, so you’ll need to turn off that option or pick a different way to name the file.

    From a Linux CLI, renaming the file would be mv Dockerfile.txt Dockerfile. That would also work with Git bash.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search