I have a simple Dockerfile, exactly as below:
FROM ubuntu:14.04 RUN apt-get update RUN apt-get -y upgrade RUN mkdir -p /root/.ssh RUN touch /root/.ssh/known_hosts RUN ssh-keyscan github.com >> /root/.ssh/known_hosts
The result of running:
docker build -no-cache -t testimage .
is:
Step 5 : RUN ssh-keyscan github.com >> /root/.ssh/known_hosts ---> Running in e11ef5962a11 /bin/sh: 1: ssh-keyscan: not found
ssh-keyscan is a command for gathering the public host keys for a number of hosts. It aids in building and verifying ssh_known_hosts files. ssh-keyscan provides a minimal interface suitable for use by shell and Perl scripts.
ssh-keyscan returns the fingerprint of a key, not the actual pub key.
The SSH method works fine for Docker containers, too. That said, you can SSH into a Docker container using Docker's built-in docker exec . If you do not need an interactive shell, you can also use the docker attach command to connect the host's stdin and stdout to the running container and execute remote commands.
You would need to install ssh first.
RUN apt-get -yq update && \ apt-get -yqq install ssh
Then, the various ssh commands, including ssh-keyscan
, would be available.
That is what I did in my sshd
image Dockerfile.
I used it to add localhost
to my .ssh/known_hosts
in order to make some test locally on the sshd
server.
As commented below by pjotr-dolphin:
If you are only after
ssh-keyscan
,openssh-client
has smaller footprint than ssh package.
Actually, package openssh-clients
for RedHat/CentOS, as commented by Oleg Neumyvakin
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With