title: Setup Docker Container with SSH server?
body: <p>I want to setup a very minimalistic alpine linux docker container with the following capabilities:</p>
  <ul>
  <li>It runs an ssh server</li>
  <li>It copies over a SSH public key of my choice to which I can then authenticate</li>
  </ul>
  <p>I looked into various options, and in the end decided to write my own small Dockerfile.
  However, I ran into some problems.</p>
  <p><strong>Dockerfile</strong></p>
  <pre><code>FROM alpine:latest
  
  RUN apk update
  RUN apk upgrade
  RUN apk add openssh-server
  
  RUN mkdir -p /var/run/sshd
  RUN mkdir -p /root/.ssh
  
  ADD authorized_keys /root/.ssh/authorized_keys
  ADD entrypoint.sh /entrypoint.sh
  RUN chmod 755 /entrypoint.sh
  
  EXPOSE 22
  CMD [&quot;/entrypoint.sh&quot;]
  </code></pre>
  <p><strong>entrypoint.sh</strong></p>
  <pre><code>#!/bin/sh
  /usr/sbin/sshd -D
  </code></pre>
  <p><strong>authorized_keys</strong></p>
  <pre><code>ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBP8cIHIPgV9QoAaSsYNGHktiP/QnWfKPOeyzjujUXgQMQLBw3jJ1EBe04Lk3FXTMxwrKk3Dxq0VhJ+Od6UwzPDg=
  </code></pre>
  <p>Starting the container gives an error: <code>sshd: no hostkeys available -- exiting</code>.
  How can I fix my Dockerfile, to ensure the ssh server is running correctly and the authorized_keys file is there. What am I missing?</p>