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
2
Answers
If the
Dockerfile
is in the working directory of your shell then no need to pass the file as an argument since thedocker build
command will automatically look for a file namedDockerfile
in the current working directory.Same thing with the context directory, you could simply replace it with
.
rather thatC: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 itYour Dockerfile is named
Dockerfile.txt
. The file should just beDockerfile
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.