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.
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 directoryCommon 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.
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
- Ensure Docker is installed and the agent user can reach the socket (group/socket mount), or use a docker-in-docker/sidecar setup.
- Install the Docker Pipeline plugin if
dockeris an unknown DSL method. - For a build-step failure, read the
RUN/COPYerror 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.