GitLab CI Runner报错:FATAL: Command sh not found 求助
Hey there, let's figure out why you're hitting that "FATAL: Command sh not found" error with your Docker-installed GitLab Runner. Given your setup (GitLab 10.4.3, Runner 10.7.2), here are the most common fixes to check step by step:
1. Confirm your job's Docker image includes a shell
First up: if your .gitlab-ci.yml specifies a custom Docker image for jobs, that image might not have /bin/sh or /bin/bash installed. For example:
- Super minimal images like
scratchdon't include any shell utilities at all. Swap to a base image likealpine:latest,debian:slim, orubuntu:latest—these all come with a shell by default. - To test locally, run
docker run --rm <your-job-image> sh -c "echo test"—if this fails, the image is missing sh, and that's the root cause.
2. Double-check your Runner's config.toml settings
Since you're using the Docker executor (the standard setup for Docker-installed Runners), make sure your config isn't pointing to a non-existent shell path. Open your config.toml and look for the runner section:
[[runners]] executor = "docker" [runners.docker] image = "alpine:latest" # This should be an image with sh shell = "sh" # Don't set this to a path that doesn't exist in the image
- If you've set
shellto something like/bin/zshbut the image doesn't have it, or made a typo (likeshh), that'll trigger the error. Stick toshorbashdepending on what your base image provides. - Also, make sure you didn't accidentally set the executor to
shellinstead ofdocker—the Runner container itself might not have the right shell setup for theshellexecutor.
3. Audit your .gitlab-ci.yml job scripts
Look for any job configurations that might be bypassing or misusing the shell:
- If you're using array syntax for
script(likescript: ["my-command"]) and the command relies on shell features (pipes, environment variables, wildcards), you'll need to wrap it in a shell explicitly:build-job: script: - sh -c "echo $CI_JOB_ID | grep -E '[0-9]+'" - Avoid setting a
shell:key in your job unless you're 100% sure that shell exists in the job's image.
4. Verify the GitLab Runner container has sh (if using shell executor)
If you're actually using the shell executor with your Dockerized Runner, the Runner's own container needs to have sh available. Check by running:
docker exec -it <your-runner-container-name> sh
If this fails, you might need to use the official GitLab Runner image (which should include sh by default) or install shell utilities inside the container (though modifying the Runner container isn't ideal—better to stick to the official image).
After making any changes, restart your Runner container to apply updates:
docker restart gitlab-runner
内容的提问来源于stack exchange,提问作者Splitframe

