How to Solve Error Message failed to read dockerfile: open /var/lib/docker/tmp/buildkit-mount047391099/Dockerfile: no such file or directory when running ‘docker-compose build’ Command in Microsoft Windows

Posted on

Introduction

Another error appear where in this article, it will be the focus of the discussion for solving the problem. So, before going on further, below is the execution of the ‘docker-compose build’ command triggering the error message :

C:\repository\docker\docker-image-apache-build-with-docker-compose>docker-compose build
[+] Building 0.1s (1/2)
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 2B 0.0s
failed to solve: rpc error: code = Unknown desc = failed to solve with frontend dockerfile.v0: failed to read dockerfile: open /var/lib/docker/tmp/buildkit-mount047391099/Dockerfile: no such file or directory

C:\repository\docker\docker-image-apache-build-with-docker-compose>

So, before going on further, the following is the description of the situation when the command execution takes place. The first one is the existence of the file with the name of ‘docker-compose.yml’. That file exist in a certain folder where the content exist below :

version: '3.9'
services:
  apache:
    build: .
    image: httpd

How to Solve Error Message no such file or directory when running ‘docker-compose build’ Command

According to the previous part, there is an error message appears. Fortunately, there is a hint for solving the problem in that error message. For a more detail focus, the following is that line containing the hint for solving that error message

failed to read dockerfile: open /var/lib/docker/tmp/buildkit-mount047391099/Dockerfile: no such file or directory

Well, it is obvious that the solution exist as part of the error message appear in the output of the command execution. In other words, the command cannot find a file with the name of ‘Dockerfile’. In order to execute the ‘docker-compose.yml’ file, specifically in the ‘build:.’ definition, it will need it. The reason is because at the time of the ‘docker-compose’ command execution select the build as the process, it will need a build descriptor file. In this context, that build descriptor file is a file with the name of ‘Dockerfile’.

So, the solution for solving the error problem is just create a file with the name of ‘Dockerfile’. But the main concern is that the ‘Dockerfile’ must directly specify the image name. Because it will override the name exist in the value of ‘image’ which in this context it is ‘httpd’. So, fill the Dockerfile with ‘httpd’ as the image file for pull operation as follows :

FROM httpd

Before executing the command which is actually building a local Docker image, just check the available local Docker image first as follows :

C:\repository\docker\docker-image-apache-build-with-docker-compose>docker image list --all
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
wordpress    latest    665d98f0f926   4 days ago    609MB
mysql        5.7       2a0961b7de03   4 days ago    462MB
mysql        latest    26fca947bf02   5 years ago   436MB

C:\repository\docker\docker-image-apache-build-with-docker-compose>

Last but not least, just execute the ‘docker-compose build’ command once more as follows :

C:\repository\docker\docker-image-apache-build-with-docker-compose>docker-compose build
[+] Building 52.1s (5/5) FINISHED
 => [internal] load build definition from Dockerfile                                                                                                                   0.0s
 => => transferring dockerfile: 47B                                                                                                                                    0.0s
 => [internal] load .dockerignore                                                                                                                                      0.0s
 => => transferring context: 2B                                                                                                                                        0.0s
 => [internal] load metadata for docker.io/library/httpd:latest                                                                                                        3.6s
 => [1/1] FROM docker.io/library/httpd@sha256:c479bec894c5a7f8878b28e52d03cc95b1e784612ecd01ac7c7394fc5fa2e6e2                                                        48.3s
 => => resolve docker.io/library/httpd@sha256:c479bec894c5a7f8878b28e52d03cc95b1e784612ecd01ac7c7394fc5fa2e6e2                                                         0.0s
 => => sha256:90bcc5e941a77b3a9aba631e1d2cfedefa212b1e53d0c8d5a7fecee3e1bd9e07 24.14MB / 24.14MB                                                                      46.3s
 => => sha256:c479bec894c5a7f8878b28e52d03cc95b1e784612ecd01ac7c7394fc5fa2e6e2 1.86kB / 1.86kB                                                                         0.0s
 => => sha256:a17755a2d2e581779d2ab6b5df6992a754a16503961f6a9d4e908c71c3d46f2d 1.36kB / 1.36kB                                                                         0.0s
 => => sha256:98f93cd0ec3b2e428f152d265d431bcb3f8a5ff56adaa5023e11a2b3b5a107e7 9.04kB / 9.04kB                                                                         0.0s
 => => sha256:77a357ba66a85136c310c166c751585c8795e74205806bf582209dc6f98704af 175B / 175B                                                                             0.3s
 => => sha256:c56c780a8904dcc67aedd611ea006ae930612b7161c8e1c811720f89a37c5d88 917.12kB / 917.12kB                                                                     1.3s
 => => extracting sha256:77a357ba66a85136c310c166c751585c8795e74205806bf582209dc6f98704af                                                                              0.0s
 => => sha256:571750298b32cd410406ba347ea18d72f983a9af1cf5f7e1a4454790036a9ba7 292B / 292B                                                                             1.5s
 => => extracting sha256:c56c780a8904dcc67aedd611ea006ae930612b7161c8e1c811720f89a37c5d88                                                                              0.1s
 => => extracting sha256:90bcc5e941a77b3a9aba631e1d2cfedefa212b1e53d0c8d5a7fecee3e1bd9e07                                                                              1.4s
 => => extracting sha256:571750298b32cd410406ba347ea18d72f983a9af1cf5f7e1a4454790036a9ba7                                                                              0.0s
 => exporting to image                                                                                                                                                 0.0s
 => => exporting layers                                                                                                                                                0.0s
 => => writing image sha256:0dde4df44f84a62b965c6ba88a0659842c911299fb084dd62f623765938d7e9d                                                                           0.0s
 => => naming to docker.io/library/httpd                                                                                                                               0.0s

Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them

C:\repository\docker\docker-image-apache-build-with-docker-compose>

After executing the ‘docker-compose build’, just check the existence of the Docker image of ‘httpd’ whether it is exist or not. The following is the execution of the command :

C:\repository\docker\docker-image-apache-build-with-docker-compose>docker image list --all
REPOSITORY TAG    IMAGE ID     CREATED     SIZE
wordpress  latest 665d98f0f926 4 days ago  609MB
mysql      5.7    2a0961b7de03 4 days ago  462MB
httpd      latest 98f93cd0ec3b 4 days ago  144MB
mysql      latest 26fca947bf02 5 years ago 436MB

C:\repository\docker\docker-image-apache-build-with-docker-compose>

There is a new local Docker image appear. In that case, the command is a success. In summary, in order to build using ‘docker-compose build’ command where it will look at the ‘docker-compose.yml’ file, it will also need file with the name of ‘Dockerfile’ to specify the image as a build target.

Leave a Reply