Skip to content
Latchkey

Jenkins docker.build Failed - Fix Docker Pipeline Image Builds

The docker.build(...) step from the Docker Pipeline plugin failed. Usually the agent has no reachable Docker daemon, the Dockerfile/build context is wrong, the image build itself errored, or the Docker Pipeline plugin is not installed.

What this error means

A pipeline fails at docker.build with Cannot connect to the Docker daemon, Cannot locate specified Dockerfile, a build-step error, or No such DSL method 'docker' when the plugin is absent.

Jenkins console
Cannot connect to the Docker daemon at unix:///var/run/docker.sock.
Is the docker daemon running?
# or
unable to prepare context: unable to evaluate symlinks in Dockerfile path:
no such file or directory

Common causes

No Docker daemon reachable on the agent

The agent has no Docker installed, the socket is not mounted, or the agent user is not in the docker group, so docker.build cannot reach the daemon.

Wrong Dockerfile or build context

The Dockerfile path or context directory passed to docker.build does not exist relative to the workspace, so the build cannot start.

Image build genuinely failed

A failing RUN, a missing base image, or a bad COPY makes the underlying docker build exit non-zero.

How to fix it

Build with a valid context on a Docker-capable agent

Run on an agent with a working Docker daemon, and pass the correct Dockerfile/context.

Jenkinsfile
node('docker') {
  checkout scm
  def img = docker.build("myapp:${env.BUILD_NUMBER}", "-f docker/Dockerfile .")
  img.inside { sh 'app --version' }
}

Provide the daemon and read the real build error

  1. Ensure Docker is installed and the agent user can reach the socket (group/socket mount), or use a docker-in-docker/sidecar setup.
  2. Install the Docker Pipeline plugin if docker is an unknown DSL method.
  3. For a build-step failure, read the RUN/COPY error above and fix the Dockerfile.

How to prevent it

  • Run docker.build only on agents with a working, accessible Docker daemon.
  • Keep the Docker Pipeline plugin installed and use correct context paths.
  • Lint/build the Dockerfile locally so build-step errors surface before CI.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →