A GitLab CI job cannot find the docker command
docker: command not foundShort answer
The job runs in a place that has no Docker client. With the Docker executor, the job image must include the docker CLI, such as the docker image, plus a daemon through docker:dind or a mounted socket. With the shell executor, Docker Engine must be installed on the runner host and the gitlab-runner user must be in the docker group.
Fix it fast
1Find out which cause you have
Find out which executor ran the job and which image it used. The first lines of the job log show both.
# first lines of the job log: # Using Docker executor with image ruby:3.3 ... # Running on <runner-name> via <host>...2Match what you see, then jump to its fix
- 1
Using Docker executor with image <something that is not docker>The job image has no docker CLIFix - 2
The CLI exists now, but docker info cannot reach a daemonDocker-in-Docker is used but the runner is not privilegedFix - 3
Using Shell executor, then docker: command not foundShell executor on a host without Docker, or without access to itFix
- 1
What does the error look like?
docker: command not founddocker info fails in before_scriptthe same script works when you run it by hand on a server
Cause 1 of 3
The job image has no docker CLI
1Check
A Docker executor job runs inside the image you name. Language images such as node or python do not carry the Docker client.
# in .gitlab-ci.yml
grep -n -E "^\s*image:|^\s*services:" .gitlab-ci.yml2Fix
Use a docker image with the CLI for the job, and add the dind service so the CLI has a daemon to talk to.
build:
image: docker:24.0.5-cli
services:
- docker:24.0.5-dind
variables:
DOCKER_TLS_CERTDIR: "/certs"
script:
- docker info
- docker build -t my-docker-image .3Verify
docker info prints client and server details at the start of the job.
docker infoConfirmed by docs.gitlab.com
Cause 2 of 3
Docker-in-Docker is used but the runner is not privileged
1Check
GitLab states that Docker-in-Docker needs privileged mode in the runner's Docker container settings, and the TLS example shares /certs/client between the containers.
grep -n -E 'privileged|volumes' config.toml # the runner's config.toml2Fix
On a runner you control, enable privileged mode and the certificate volume, then restart the runner. If you cannot, use socket binding or a build tool that needs no daemon, as GitLab's page describes.
[[runners]]
executor = "docker"
[runners.docker]
privileged = true
volumes = ["/certs/client", "/cache"]3Verify
Run the job again and read the docker info output.
docker infoConfirmed by docs.gitlab.com
Cause 3 of 3
Shell executor on a host without Docker, or without access to it
1Check
With the shell executor the job runs as the gitlab-runner user on the host. Docker Engine has to be installed there, and that user has to be in the docker group.
which docker
id gitlab-runner2Fix
Install Docker Engine on the runner host, add gitlab-runner to the docker group, and confirm with docker info as that user. GitLab warns this group gives the user root-level power on the host.
sudo usermod -aG docker gitlab-runner
sudo -u gitlab-runner -H docker info3Verify
Run the pipeline again.
sudo -u gitlab-runner -H docker infoConfirmed by docs.gitlab.com
How do I stop it coming back?
- Give build jobs a tag so only runners set up for Docker pick them up.
- Pin the docker and dind images to the same version.
- Put docker info in before_script so a missing client or daemon fails in the first second.
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