Skip to content

Resolving Docker BuildKit ERROR on Ubuntu: Installing the buildx Component

When attempting to run docker build and encounter an error indicating that “BuildKit is enabled but the buildx component is missing or broken,” follow these steps for resolution. This guide presumes a basic understanding of terminal commands in Ubuntu environment, along with Docker installation procedures.

Problem Explanation:

The encountered issue suggests BuildKit’s necessity alongside its ‘buildx’ subcomponent to construct images effectively using this modern feature within the docker command line interface (CLI).

Here is an error example for reference:

ERROR: buildkit:[Errno 2] No such file or directory
failed to solve: executor failed running [npx tailor -k buildx-compatible]: runc process has too many levels of nested page faults; paging fails.
BuildKit is enabled but the buildx component (required for BuildKit) appears broken, missing, unversioned and unsourced in your system's Docker setup—installation or sourcing needed to resolve this issue. 

This error indicates that after an attempt at removing container data using a command like sudo rm -rf ~/.local/share/containers/ the necessary build tools are not functioning correctly, leading BuildKit and its required component ‘buildx’ into failure when trying out Docker image builds on Ubuntu.

Solution Steps:

  1. Remove Existing Installation (if it exists): If you have any pre-installed versions of docker from third party sources or other environments like a virtual machine, remove them for safety reasons as follows:
    $ for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do sudo apt-get remove "$pkg"; done
    ```  This will clear all existing Docker packages from your system but is not expected to make a direct impact on resolving the BuildKit error described above, unless they interfere with proper installation of buildx. However, it's always good practice for cleanup:  
    
    
  2. Reinstall docker-ce (preferred): Reinstate docker-ce using apt package management system if removed previously or to correct any issues caused by repository corruption during upgrade as follows:
    sudo apt-get install --reinstall docker-ce
    ```   This should reinitialize Docker, resolving most of the standard installation errors and preparing your environment for BuildKit functionalities. If this method does not resolve our issue possibly due to repository problems (common during system upgrades), proceed with further steps: 
    
  3. Reconfigure Apt Repositories if necessary by adding back Docker’s official GPG key as well ensuring the correct repositories are added and updated accordingly in your Ubuntu setup which can sometimes get disrupted upon fresh installation or upgrade, this is performed through following commands:
        sudo apt-get update  # ensure package lists are up to date.
    
        1) Import Docker's GPG key (required for validating packages):
            curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg  # create and open the trusted keys directory, import GPG key here to sign Docker releases  
        chmod a+r /etc/apt/keyrings/docker.gpg     # ensure that added signature is readable by root (trusted users)   
        2) Add Ubuntu's official docker repository: 
            echo \
                "deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker-ce.list  # add repository for Ubuntu, replacing '$(lsb_release -cs)' with your specific version of ubuntu
        3) Refresh apt's package lists:  
            sudo apt update     # ensure the newly added repositories are up to date and available in APT sources     
    ```4. **Reinstall docker-ce** after ensuring that Docker repository has been properly sourced, this should restore your system’severything regarding building images with BuildKit:  
        `sudo apt install --reinstall docker-ce`  # reinstalls the package using correct repositories and dependencies   
    
  4. Verify Installation to ensure all went smoothly after these steps by executing a simple Docker command such as running an existing container or build image, for instance:
    shell sudo docker run hello-world # this should output 'Hello from Docker:' followed with some message indicating successful installation of the default Debian "hello world" image. This is often used to verify whether your system has properly installed and configured Docker after resolving any previous errors:
    Remember, proper configuration depends on keeping up-to-date package lists (step by step process above) as well ensuring integrity of packages signed with trusted keys which adds an extra layer of security in modern environments. This way even if a repository becomes compromised or its sources are unreliable it would not pose threat to your system, rather apt maintains good level of reliability and correctness during installation processes:

Following these steps should help resolve the BuildKit ERROR on Ubuntu for building Docker images. If issues persist consult with official documentation (https://docs.docker.com/go/), or seek expert advice to ensure all necessary components are correctly installed, especially when working in complex environments and configurations where different systems might behave differently:


Previous Post
Understanding start dev in Keycloak Docker Conta
Next Post
Unraveling Git Exceptions in Jenkins Pipeline Scri