Probable bug - 'docker buildx build' not recognized in Jenkins Pipeline

I am new here, first post ever.

Jenkins setup:

jenkins: 2.555.1
java: openjdk 21.0.11 2026-04-21
OpenJDK Runtime Environment (build 21.0.11+10-1-deb13u2-Debian)
OpenJDK 64-Bit Server VM (build 21.0.11+10-1-deb13u2-Debian, mixed mode, sharing)
Installation methods:

  1. APT repository (main linux system)
  2. Docker image (jenkins in docker - please see below)
    Browser: Firefox 150.0.1 (64-bit)
    scm: not used here

System: MXLinux 25.1:
Kernel: 6.12.85+deb13-amd64 arch: x86_64 bits: 64 compiler: gcc v: 14.2.0 clocksource: tsc
avail: hpet,acpi_pm parameters: BOOT_IMAGE=/boot/vmlinuz-6.12.85+deb13-amd64 root=UUID=
ro quiet splash
Desktop: Xfce v: 4.20.1 tk: Gtk v: 3.24.48 wm: xfwm4 v: 4.20.0 with: docker,xfce4-panel
tools: xfce4-screensaver vt: 7 dm: LightDM v: 1.32.0 Distro: MX-25.1_Xfce_x64 Infinity January
18 2026 base: Debian GNU/Linux 13 (trixie)
Machine:
Type: Desktop System: ASUS product: N/A v: N/A serial:
Mobo: ASUSTeK model: ROG STRIX B550-F GAMING v: Rev X.0x serial:
part-nu: SKU uuid: UEFI: American Megatrends v: 3611 date: 09/29/2024
CPU:
Info: model: AMD Ryzen 7 5800XT bits: 64 type: MT MCP arch: Zen 3+ gen: 3 level: v3 note: check
built: 2022 process: TSMC n6 (7nm) family: 0x19 (25) model-id: 0x21 (33) stepping: 2
microcode: 0xA201210
Topology: cpus: 1x dies: 1 clusters: 1 cores: 8 threads: 16 tpc: 2 smt: enabled cache:
L1: 512 KiB desc: d-8x32 KiB; i-8x32 KiB L2: 4 MiB desc: 8x512 KiB L3: 32 MiB desc: 1x32 MiB

Plugins:

Plugin:ant, Plugin:antisamy-markup-formatter, Plugin:apache-httpcomponents-client-4-api, Plugin:apache-httpcomponents-client-5-api, Plugin:asm-api, Plugin:authentication-tokens, Plugin:bootstrap5-api, Plugin:bouncycastle-api, Plugin:branch-api, Plugin:build-timeout, Plugin:caffeine-api, Plugin:checks-api, Plugin:cloud-stats, Plugin:cloudbees-folder, Plugin:commons-compress-api, Plugin:commons-lang3-api, Plugin:commons-text-api, Plugin:credentials-binding, Plugin:credentials, Plugin:dark-theme, Plugin:display-url-api, Plugin:docker-commons, Plugin:docker-java-api, Plugin:docker-workflow, Plugin:durable-task, Plugin:echarts-api, Plugin:eddsa-api, Plugin:email-ext, Plugin:font-awesome-api, Plugin:git-client, Plugin:git, Plugin:github-api, Plugin:github-branch-source, Plugin:github, Plugin:gradle, Plugin:gson-api, Plugin:instance-identity, Plugin:ionicons-api, Plugin:jackson-annotations2-api, Plugin:jackson2-api, Plugin:jackson3-api, Plugin:jakarta-activation-api, Plugin:jakarta-mail-api, Plugin:jakarta-xml-bind-api, Plugin:javax-activation-api, Plugin:jaxb, Plugin:jjwt-api, Plugin:joda-time-api, Plugin:jquery3-api, Plugin:json-api, Plugin:json-path-api, Plugin:jsoup, Plugin:junit, Plugin:ldap, Plugin:mailer, Plugin:matrix-auth, Plugin:matrix-project, Plugin:metrics, Plugin:mina-sshd-api-common, Plugin:mina-sshd-api-core, Plugin:okhttp-api, Plugin:pipeline-build-step, Plugin:pipeline-github-lib, Plugin:pipeline-graph-view, Plugin:pipeline-groovy-lib, Plugin:pipeline-input-step, Plugin:pipeline-milestone-step, Plugin:pipeline-model-api, Plugin:pipeline-model-definition, Plugin:pipeline-model-extensions, Plugin:pipeline-stage-step, Plugin:pipeline-stage-tags-metadata, Plugin:plain-credentials, Plugin:plugin-util-api, Plugin:prism-api, Plugin:resource-disposer, Plugin:scm-api, Plugin:script-security, Plugin:snakeyaml-api, Plugin:snakeyaml-engine-api, Plugin:ssh-credentials, Plugin:ssh-slaves, Plugin:structs, Plugin:theme-manager, Plugin:timestamper, Plugin:token-macro, Plugin:trilead-api, Plugin:variant, Plugin:woodstox-core-api, Plugin:workflow-aggregator, Plugin:workflow-api, Plugin:workflow-basic-steps, Plugin:workflow-cps, Plugin:workflow-durable-task-step, Plugin:workflow-job, Plugin:workflow-multibranch, Plugin:workflow-scm-step, Plugin:workflow-step-api, Plugin:workflow-support, Plugin:ws-cleanup

The issue is getting the command ā€˜docker buildx build’, as opposed to ā€˜docker build’, to work in my jenkins pipeline/docker setup.

The reason is "docker build’ is to be deprecated and removed, and I am addressing the issue of impending technical debt.

Compare these two lines in ā€˜Build Docker image’ stage (please see code below):

  • ā€˜docker build -t ${IMAGE_NAME} .’ works in jenkins and on my main system (a debian-derived linux distro called ā€œMXLinuxā€)
  • ā€˜docker buildx build -t ${IMAGE_NAME} --load .’ does not work in jenkins, however does work on my main system with the Dockerfiles below

…and ā€˜buildx’ is not recognized on jenkins, even though ā€˜buildx’ is installed on my main system and should be accessible via docker.sock in a DooD setup. Puzzling, as ā€˜docker build’ is an alias for ā€˜docker buildx build’.

The context is a custom dockerized jenkins container built for Docker-outside-of-Docker (DooD) architecture, where the jenkins Docker image installs docker-ce-cli , not full Docker, as well as maven.

Here is the Dockerfile code for that purpose:

##############################################

### Custom Jenkins controller with Maven + Docker CLI (DooD)
FROM jenkins/jenkins:lts

USER root

### Basic tools + Maven
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
        maven \
        ca-certificates \
        curl \
        gnupg && \
    rm -rf /var/lib/apt/lists/*

### Install Docker CLI only (no daemon) from Docker's official repo
RUN install -m 0755 -d /etc/apt/keyrings && \
    curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc && \
    chmod a+r /etc/apt/keyrings/docker.asc && \
    echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian $(. /etc/os-release && echo \"$VERSION_CODENAME\") stable" > /etc/apt/sources.list.d/docker.list && \
    apt-get update && \
    apt-get install -y --no-install-recommends docker-ce-cli && \
    rm -rf /var/lib/apt/lists/*

### Drop back to the Jenkins user
USER jenkins

##############################################

This Docker image is instantiated as a jenkins controller Docker container with this command:

##############################################

docker run -d \
  --name mvn-jenkins \
  --group-add "$(getent group docker | cut -d: -f3)" \
  --restart unless-stopped \
  -p 8082:8080 \
  -p 50002:50000 \
  -v jenkins_home:/var/jenkins_home \
  -v /home/ra/.ssh:/var/jenkins_home/.ssh \
  -v /var/run/docker.sock:/var/run/docker.sock \
  jenkins-with-maven-docker

##############################################

My Jenkins controller plugins include:

Docker API, Docker commons, Docker and Docker pipeline.

My Jenkinsfile declarative pipeline uses a Docker agent, instantiated with this Dockerfile:

##############################################

FROM maven:3.9.15-amazoncorretto-21-debian

USER root

### Install Docker CLI only
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
        ca-certificates \
        curl \
        gnupg && \
    rm -rf /var/lib/apt/lists/* && \
    install -m 0755 -d /etc/apt/keyrings && \
    curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc && \
    chmod a+r /etc/apt/keyrings/docker.asc && \
    echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian $(. /etc/os-release && echo \"$VERSION_CODENAME\") stable" > /etc/apt/sources.list.d/docker.list && \
    apt-get update && \
    apt-get install -y --no-install-recommends docker-ce-cli && \
    rm -rf /var/lib/apt/lists/*

### Use a non-root UID (Jenkins agents typically run as 1000)
RUN useradd -u 1000 -m jenkins
RUN groupadd docker || true
RUN usermod -aG docker jenkins

USER jenkins
WORKDIR /home/jenkins

##############################################

Here is the problematic Jenkinsfile, I draw your attention to the agent and stage(ā€˜Build Docker image’):

##############################################

pipeline {
	
	// must first manually extend permissions 
	// for /run/docker.sock on main system to 'other':
	// sudo chmod a+rw /run/docker.sock
	agent {
  		docker {
    		image 'maven-docker-agent'
        	args '-v /var/run/docker.sock:/var/run/docker.sock'
  		}
	}

    environment {
        IMAGE_NAME = 'java-hello:local'
        CONTAINER_NAME = 'java-hello'
    }

    stages {
    	stage('Remove old Maven project') {
  			steps {
    			deleteDir()
  			}
		}
        stage('Generate new Maven project') {
            steps {
                sh '''
                    mvn archetype:generate \
                      -DgroupId=com.mycompany.app \
                      -DartifactId=my-app \
                      -DarchetypeArtifactId=maven-archetype-quickstart \
                      -DarchetypeVersion=1.5 \
                      -DinteractiveMode=false

                    echo "completed mvn archetype:generate"
                '''
            }
        }
        stage('Build JAR') {
            steps {
                dir('my-app') {
                    sh '''
                        mvn -B -DskipTests clean package
                        echo "built JAR"
                    '''
                }
            }
        }
// when using EOF in groovy, put all lines up against left margin
// to eliminate whitespace (see below)
        stage('Prepare Docker context') {
            steps {
                dir('my-app') {
sh '''
cat > Dockerfile <<'EOF'
FROM eclipse-temurin:25-jre-ubi10-minimal
WORKDIR /app
COPY target/my-app-1.0-SNAPSHOT.jar /app/app.jar
ENTRYPOINT ["java","-cp","/app/app.jar","com.mycompany.app.App"]
EOF

echo "built Dockerfile"

cat > .dockerignore <<'EOF'
target/*
!target/my-app-1.0-SNAPSHOT.jar
.git
.gitignore
EOF

echo "built .dockerignore"
'''
                }
            }
        }
        stage('Build Docker image') {
            steps {
                dir('my-app') {
                    sh '''
                        docker build -t ${IMAGE_NAME} .
                        # docker buildx build -t ${IMAGE_NAME} --load .
                        echo "built Docker image ${IMAGE_NAME}"
                    '''
                }
            }
        }
        stage('Run container') {
            steps {
                sh '''
                    echo "--- Container output below ---"
                    docker run --rm --name ${CONTAINER_NAME} ${IMAGE_NAME}
                '''
            }
        }
    }
}

I tried different variations of the buildx command, to no avail, and experimented with the ā€˜Docker plugin’, however I am unsure if it is right for this situation or if I followed the Docker plugin instructions correctly.

Has anyone gotten ā€˜docker buildx’ to work in a DooD scenario?

I have docker-buildx-plugin installed as a separate package on my Ubuntu computer. That is in additional to docker-ce-cli. They are separate packages as far as I know.

Thanks, Mark. That worked.

I added this line of code to both Dockerfiles:

apt-get install -y --no-install-recommends docker-buildx-plugin && \

This issue is resolved.