在docker运行期间创build新的SSH密钥
有没有办法每次运行一个容器时生成一个新的SSH服务器密钥? 我最初以为我可以将其添加到Dockerfile,但我认为这只是指图像构build过程。 每次运行容器时,我都需要一个新的密钥。
这些就是我为创造我的形象所做的。
https://docs.docker.com/engine/examples/running_ssh_service/
尝试这个
CMD /bin/rm -v /etc/ssh/ssh_host_* && dpkg-reconfigure openssh-server && /usr/sbin/sshd -D
这里有一个自定义入口点脚本的小示例设置,可以在开始时dynamic编辑您的容器。
Dockerfile:
FROM SOMETHING RUN mkdir /start ADD entrypoint.sh /start/entrypoint.sh # set the entry point to custom script ENTRYPOINT ["/start/entrypoint.sh"] # define pseudo command, which is recognized by entry point script CMD ["sshd"]
这将复制并将入口点设置为“entrypoint.sh”,将CMD设置为“sshd”。
这里的entrypoint.sh:
#!/bin/bash # Fail fast, including pipelines set -eo pipefail ... do your stuff like SSH key creation if [ "$1" = 'sshd' ]; then exec /usr/sbin/sshd -D fi # if CMD is not sshd execute the CMD. # Good for debugging because you can pass /bin/bash for example as CMD exec "$@"
现在,您可以在开始时在入口点脚本中input您的ssh密钥,并在提供正确的CMD的情况下运行您的应用程序。
为了debugging容器,你现在可以提供“/ bin / bash”例如CMD到docker run命令。 这将给你一个bash shell而不是启动你的应用程序,但你的定制仍然完成。
开始SSHD:
docker run myImageName
如果入口点脚本正确运行,则debugging:
docker run -i -t myImageName /bin/bash