Introduction
As exist in the title of this article, there is a specific error appear upon building a docker image. In this article, the focus of the content is to be able to solve that error. It appear upon executing the following command in order to build the docker image :
C:\repository\django\project\builder>docker-compose build Building web [+] Building 0.1s (2/2) FINISHED => [internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 2B 0.0s => [internal] load .dockerignore 0.1s => => transferring context: 2B 0.0s failed to solve with frontend dockerfile.v0: failed to read dockerfile: open /var/lib/docker/tmp/buildkit-mount498198349/Dockerfile: no such file or directory ERROR: Service 'web' failed to build : Build fail C:\repository\django\project\builder>
Solution
Basically, before solving the error message as exist in the above part. The error appear so that it ends in failure for building the docker image. The following is the actual directory structure of the ‘builder’ folder :
C:\repository\django\project\builder>tree /A /F Folder PATH listing Volume serial number is FC64-E91F C:. | docker-compose.yml C:\repository\django\project\builder>
After searching Google for a solution, actually the solution for solving the above problem is simple. It is because of the non-existence of the ‘dockerfile’ which is normally present as ‘DockerFile’. It is exist as part of the error message above which is ‘failed to read dockerfile’. In that case, in order to solve the problem, just provide the ‘DockerFile’. The following is the content of the ‘DockerFile’ with a simple content :
# pull image FROM centos # set work directory WORKDIR /var/www
Running the command again once more to build the image is a success. It is after the existence of the ‘DockerFile’ as in the following command execution :
C:\repository\django\project\builder>docker-compose build Building web [+] Building 0.3s (6/6) FINISHED => [internal] load build definition from Dockerfile 0.2s => => transferring dockerfile: 352B 0.1s => [internal] load .dockerignore 0.2s => => transferring context: 2B 0.1s => [internal] load metadata for docker.io/library/centos:latest 0.0s => [1/2] FROM docker.io/library/centos 0.0s => CACHED [2/2] WORKDIR /var/www 0.0s => exporting to image 0.0s => => exporting layers 0.0s => => writing image sha256:7c055c0a93f918fb6ad256163dc9c379ae13aee423ffaebaa251e174509636bb 0.0s => => naming to docker.io/library/builder_web 0.0s Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them C:\repository\django\project\builder>
Last but not least, just execute the built image resulted from the execution of the previous command. Just run the following command to do it :
C:\repository\django\project\builder>docker run -it --name mycontainer -d bash builder_web f25f99cd8d9583486db10ccc59fec999e7ca3367b26f1c8868de5b0e876b515b C:\repository\django\project\builder>
After executing the above command to create a new running container, check it after. It is important to check if the container exist or not as follows :
C:\repository\django\project\builder>docker container list --all CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f25f99cd8d95 bash "docker-entrypoint.s…" 17 seconds ago Exited (127) 8 seconds ago mycontainer 44fdcb5a7482 centos "/bin/bash" 7 hours ago Up 7 hours 0.0.0.0:80->80/tcp sinergi 8a52dcce139c registry "/entrypoint.sh /etc…" 8 days ago Up 42 hours 0.0.0.0:5000->5000/tcp hub.local C:\repository\django\project\builder>
Finally, the last command below is just a command which is trying to prove that the container above exist but it is not running anymore. Because according to the output above, it has already exited. The command for executing a process for an already running container exist as follows :
C:\repository\django\project\builder>docker exec -it mycontainer bash Error response from daemon: Container f25f99cd8d9583486db10ccc59fec999e7ca3367b26f1c8868de5b0e876b515b is not running C:\repository\django\project\builder>
bro shit doenst work
Sorry then if the solution does not work. Basically, the error above appear because Dockerfile does not exist in the path where the ‘docker’ command executed. In that case, just provide the appropriate Dockerfile in that path.