Solution for Docker issue failed to solve: rpc error: code = unknown desc

docker-error-failed-to-solve-with-frontend-dockerfile

This post presents a solution to an error I encountered recently with Docker when trying to bring up a docker container using docker-compose.

Skip to the solution that resolved this issue for me

The solution in the post helped me fix the Docker issue failed to solve: rpc error: code = unknown desc = failed to solve with frontend dockerfile v0

Docker Error Messages

If you have been having the same problem as me, you might get one of the following error messages from Docker:

docker failed to solve rpc error code = unknown desc

docker failed to solve with frontend dockerfile.v0

failed to solve: rpc error: code = unknown desc = failed to solve with frontend dockerfile v0

Docker build error: failed to solve with the frontend dockerfile

Problem

The problem with Docker was happening when I was trying to bring up docker using a docker-compose file. I was using a command similar to this one:

> sudo -E docker-compose -f docker-compose.yml -f docker-compose.local.yml up --build

The error message I got was as follows:

ayesh@computer:$ sudo docker-compose -f docker-compose.local.yml up -d
[+] Building 0.0s (1/2)
 => [internal] load build definition from data                    0.0s
 => => transferring dockerfile: 48.90kB                           0.0s
failed to solve: rpc error: code = Unknown desc = 
failed to solve with frontend dockerfile.v0: failed to read dockerfile:
read /var/lib/docker/tmp/buildkit-mount939660890/data-extraction: 
is a directory

I tried a few variations to bring up the docker containers

> sudo docker-compose -f docker-compose.local.yml up -d

I got similar error messages from docker:

ayesh@computer:$ sudo docker-compose -f docker-compose.local.yml up -d 
[+] Building 0.6s (2/2) FINISHED
 => [internal] load build definition from data                    0.6s
 => => transferring dockerfile: 59.91MB                           0.6s
 => [internal] load .dockerignore                                 0.0s
 => => transferring context: 2B                                   0.0s
failed to solve: rpc error: code = Unknown desc = 
failed to solve with frontend dockerfile.v0: failed to read dockerfile: 
read /var/lib/docker/tmp/buildkit-mount070889300/data-extraction: 
is a directory

I also tried to clear out existing docker containers and images from the cache. > sudo docker system prune -a -f This did not work when I tried to rebuild docker containers as above.

The consistent error from each of the commands I tried that failed seemed to be not finding a docker file.

failed to solve: 
rpc error: code = Unknown desc = 
failed to solve with frontend dockerfile.v0: 
failed to read dockerfile: 
read /var/lib/docker/tmp/buildkit-mount070889300/data: 
is a directory

Docker Setup

You can skip to the solution here, as this section helps check if docker is correctly installed.

The first step you can try is to make sure you can actually run a ‘hello world’ docker image successfully. You can do this by executing the following command:

> docker run hello-world

The output of this command should be as follows:

ayesh@computer:$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete 
Digest: sha256:9ade9cc2e26189a19c2e8854b9c8f1e14829b51c55a630ee675a5
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your 
installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the 
    Docker Hub. (amd64)
 3. The Docker daemon created a new container from that image which 
    runs the executable that produces the output you are 
    currently reading.
 4. The Docker daemon streamed that output to the Docker client, 
    which sent it to your terminal.

To try something more ambitious, 
you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

As suggested in the output of the docker hello world example, you can try a more advanced docker test, which would be to run the latest ubuntu image and execute command via the bash terminal in ubuntu.

> docker run -it ubuntu bash

The output should be as follow, and should give you terminal access as the root user.

ayesh@computer:~$ sudo docker run -it ubuntu bash
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
7b1a6ab2e44d: Pull complete 
Digest: sha256:626ffe58f6e7566e00254b638eb7e0f3b
Status: Downloaded newer image for ubuntu:latest
root@caf8018236b0:/# 

Solution

The solution is to explicitly give the name of the docker file in the docker-compose.yml. Change how you specify the location of your dockerfile from dockerfile: . to dockerfile: Dockerfile

This is an sample of the docker-compose file which did not work on Ubuntu 20.04 or Windows10, it only seems to work on MacOS only. As you can see, the dockerfile location is specified as a ‘.’

version: "3"
...
    build:
      context: ../.
      dockerfile: .

The sample docker-compose file shown below is a working cross platform file, which works on MacOS, Ubuntu, Windows10.

version: "3"
...
    build:
      context: ../.
      dockerfile: Dockerfile

As you can see, the line specifying the dockerfile has been changed from a dot ‘.’ to the explicit file name, in my case, it was ‘Dockerfile’.

This also works with lower and uppercase docker files as dockerfile: Dockerfile or dockerfile: dockerfile

Conclusion

The problem seemed to originate from the cross platform development and testing of the docker-compose script, between MacOS and Ubuntu / Window10 using version 3 of docker-compose. In the scenario of specifying the location of the dockerfile.

The original docker-compose file was built on MacOS, I was trying to use the same file but on Ubuntu 20.04. I believe this same problem can also occur if also trying to use docker-compose developed using MacOS on Windows10.

If you are using MacOS, then this docker-compose file will most likely run without any problems (if you do not have any other unrelated problems).

You can read more about how I have used docker in my other projects.

Creating your first programming language is easier than you think,
...also looks great on your resume/cv.