ssh-keyscan is missing inside your Docker build
/bin/sh: ssh-keyscan: not foundShort answer
Slim base images do not include the OpenSSH client, and ssh-keyscan is part of it. Install the client package in the same stage that runs the command: openssh-client with apt-get on Debian or Ubuntu, openssh-client with apk on Alpine. In a multi-stage build, install it in the stage that calls ssh-keyscan, not an earlier one.
Fix it fast
1Find out which cause you have
Find out which base image the failing stage uses and whether the tool exists there. Run a throwaway container from the same image.
docker run --rm IMAGE_NAME sh -c 'command -v ssh-keyscan || echo missing'2Match what you see, then jump to its fix
- 1
ssh-keyscan: command not found in a stage that starts FROM debian, ubuntu or a node/python image based on themDebian or Ubuntu base image without the OpenSSH clientFix - 2
/bin/sh: ssh-keyscan: not found (the shell wording of Alpine's busybox sh)Alpine base image without the OpenSSH clientFix - 3
ssh-keyscan works in the builder stage but fails in the final stageThe tool was installed in a different build stageFix
- 1
What does the error look like?
/bin/sh: ssh-keyscan: not foundssh-keyscan: command not found
Cause 1 of 3
Debian or Ubuntu base image without the OpenSSH client
1Check
The Debian package openssh-client ships ssh-keyscan together with ssh, scp and sftp. Check whether it is installed in the image.
docker run --rm IMAGE_NAME dpkg -s openssh-client2Fix
Install the package in the Dockerfile. Keep apt-get update and apt-get install in one RUN so the package index is never stale.
RUN apt-get update && apt-get install -y --no-install-recommends openssh-client \
&& rm -rf /var/lib/apt/lists/*3Verify
Rebuild and run the command that failed.
docker build -t my-app .Confirmed by packages.debian.org
Cause 2 of 3
Alpine base image without the OpenSSH client
1Check
On Alpine the client is split into packages. The ssh-keyscan binary is listed in the openssh-client-common package, and the openssh-client name installs the client with it. Check whether the command exists in the image.
docker run --rm IMAGE_NAME sh -c 'command -v ssh-keyscan || echo missing'2Fix
Add the client with apk. apk add downloads the package from the repositories listed in /etc/apk/repositories.
RUN apk add --no-cache openssh-client3Verify
Run the tool once to confirm it is on the PATH.
docker run --rm my-app sh -c 'command -v ssh-keyscan'Confirmed by pkgs.alpinelinux.org
Cause 3 of 3
The tool was installed in a different build stage
1Check
Every FROM starts a new stage from its own base image. Packages installed in an earlier stage are not there unless that stage is used as the base. Look at which stage the failing RUN belongs to.
grep -n -E '^(FROM|RUN).*(ssh-keyscan|openssh)' Dockerfile2Fix
Install the client in the stage that runs ssh-keyscan. If you only need the known_hosts file in the final image, generate it in the builder stage and copy that file across.
FROM debian:stable-slim AS keys
RUN apt-get update && apt-get install -y --no-install-recommends openssh-client
RUN mkdir -p /out && ssh-keyscan -t ed25519 github.com > /out/known_hosts
FROM debian:stable-slim
COPY --from=keys /out/known_hosts /root/.ssh/known_hosts3Verify
Build the whole file, not only the first stage.
docker build --no-cache -t my-app .Confirmed by docs.docker.com
How do I stop it coming back?
- List every command-line tool a RUN step uses in the same stage as an explicit package install.
- Check host keys against the provider's published fingerprints; ssh-keyscan cannot verify the keys it fetches.
- Keep apt-get update and apt-get install together in one RUN.
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