A Jenkins pipeline stage that runs docker cannot find the docker command
sh step in the pipeline reports that docker is not foundShort answer
Jenkins in a container ships without the Docker client, so a sh step that calls docker fails. Check three things: the docker CLI exists inside the Jenkins image, the CLI can reach a daemon through DOCKER_HOST, and the Docker Pipeline plugin is installed for agent { docker }. Fix whichever one is missing.
Fix it fast
1Find out which cause you have
Open a shell in the running Jenkins container and ask whether the CLI is there and where it points.
docker exec -it jenkins bash -c 'which docker; docker version; echo "DOCKER_HOST=$DOCKER_HOST"'2Match what you see, then jump to its fix
- 1
which docker prints nothing inside the containerThe Jenkins image has no Docker CLIFix - 2
docker --version works, docker version fails on the server partThe CLI is installed but has no daemon to talk toFix - 3
Only agent { docker { ... } } fails; plain sh steps that call docker are fineThe Docker Pipeline plugin is missingFix
- 1
What does the error look like?
sh step in the pipeline reports that docker is not foundJenkins cannot use the docker agent type in Declarative Pipeline
Cause 1 of 3
The Jenkins image has no Docker CLI
1Check
The official jenkins/jenkins image does not include the Docker client. Pipeline steps run inside that container, so they only see what the image holds.
docker exec jenkins which docker2Fix
Build your own image from the official one and install docker-ce-cli from Docker's apt repository, as the Jenkins install guide does. Run the new image in place of the old one.
FROM jenkins/jenkins:2.580.2-jdk21
USER root
RUN apt-get update && apt-get install -y lsb-release ca-certificates curl && \
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" \
| tee /etc/apt/sources.list.d/docker.list > /dev/null && \
apt-get update && apt-get install -y docker-ce-cli && \
apt-get clean && rm -rf /var/lib/apt/lists/*
USER jenkins3Verify
Build the image, start a container from it and run the client.
docker build -t myjenkins:2.580.2-1 .
docker run --rm myjenkins:2.580.2-1 docker --versionConfirmed by jenkins.io
Cause 2 of 3
The CLI is installed but has no daemon to talk to
1Check
A client alone does nothing. In the Jenkins guide the controller reaches a separate docker:dind daemon over TCP, driven by three environment variables. If they are missing from your docker run, the client finds no daemon.
docker exec jenkins env | grep DOCKER2Fix
Run the docker:dind container on a shared network with the alias docker, then start Jenkins on the same network with DOCKER_HOST, DOCKER_CERT_PATH and DOCKER_TLS_VERIFY and the shared certs volume mounted read-only.
docker network create jenkins
docker run --name jenkins-docker --rm --detach \
--privileged --network jenkins --network-alias docker \
--env DOCKER_TLS_CERTDIR=/certs \
--volume jenkins-docker-certs:/certs/client \
--volume jenkins-data:/var/jenkins_home \
--publish 2376:2376 \
docker:dind --storage-driver overlay2
docker run --name jenkins --restart=on-failure --detach \
--network jenkins --env DOCKER_HOST=tcp://docker:2376 \
--env DOCKER_CERT_PATH=/certs/client --env DOCKER_TLS_VERIFY=1 \
--publish 8080:8080 --publish 50000:50000 \
--volume jenkins-data:/var/jenkins_home \
--volume jenkins-docker-certs:/certs/client:ro \
myjenkins:2.580.2-13Verify
The client now sees a server.
docker exec jenkins docker versionConfirmed by jenkins.io
Cause 3 of 3
The Docker Pipeline plugin is missing
1Check
The Jenkins docs say that without the Docker Pipeline plugin, Jenkins cannot use the docker agent type in Declarative Pipeline. In Manage Jenkins, Plugins, Installed plugins, look for Docker Pipeline.
# Manage Jenkins > Plugins > Installed plugins: search for Docker Pipeline2Fix
Install the plugin in the image so it survives rebuilds, then rebuild and restart.
# last line of the Dockerfile, after USER jenkins
RUN jenkins-plugin-cli --plugins "docker-workflow json-path-api"3Verify
Run a pipeline that uses the docker agent; the stage starts the container and runs its steps inside it.
pipeline {
agent { docker { image 'node:22-alpine' } }
stages { stage('Test') { steps { sh 'node --version' } } }
}Confirmed by jenkins.io
How do I stop it coming back?
- Keep the Jenkins Dockerfile in version control and pin the base image tag.
- List plugins in the Dockerfile with jenkins-plugin-cli so a rebuild never drops one.
- Use named volumes for jenkins-data and the certs, so replacing the container loses nothing.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Servers
apk cannot find py-pip in an Alpine Docker image
py-pip (no such package):
On current Alpine releases there is no package called py-pip.
2 causes, each with a fixServers
ng serve runs in the container but localhost:4200 does not open
The browser cannot open localhost:4200 although ng serve is running in the container
ng serve listens on localhost by default, which inside a container is the container itself.
3 causes, each with a fixServers
Angular routes return 404 from nginx when you refresh or open a link
The home page loads, but refreshing /some/route shows an nginx 404
Angular routes like /users/42 are not files, so nginx looks for them on disk and returns 404.
3 causes, each with a fixServers
AH00558: Apache in Docker cannot reliably determine its fully qualified domain name
Set the 'ServerName' directive globally to suppress this message
AH00558 is a warning, not a crash.
2 causes, each with a fixServers
Apache in a Docker container logs AH01114 when it proxies to a backend
AH01114: HTTP: failed to make connection to backend: api
Apache's proxy worker could not open a connection to the address in ProxyPass.
5 causes, each with a fixServers
Apache logs SIGWINCH and exits on its own
the httpd container stops although nothing crashed
SIGWINCH is Apache's graceful-stop signal.
2 causes, each with a fix