Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

A GitLab CI job cannot find the docker command

Errordocker: command not found

Short 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.

  • Applies to GitLab 18.x, GitLab Runner 18.x, Docker Engine 27
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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>...
  2. 2Match what you see, then jump to its fix

    1. 1Using Docker executor with image <something that is not docker>The job image has no docker CLIFix
    2. 2The CLI exists now, but docker info cannot reach a daemonDocker-in-Docker is used but the runner is not privilegedFix
    3. 3Using Shell executor, then docker: command not foundShell executor on a host without Docker, or without access to itFix

What does the error look like?

  • docker: command not found
  • docker info fails in before_script
  • the 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.yml

2Fix

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 info

Confirmed by docs.gitlab.com

Did this fix it?

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.toml

2Fix

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 info

Confirmed by docs.gitlab.com

Did this fix it?

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-runner

2Fix

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 info

3Verify

Run the pipeline again.

sudo -u gitlab-runner -H docker info

Confirmed by docs.gitlab.com

Did this fix it?

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

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.