dockerdockerfilessh-keysknown-hosts

Git clone inside of newly created container - problem with known_hosts


I would like to ask how to solve the problem that when I try to git clone ... in the container it will fail due to that the server is not in known_hosts. Is there way how to force "yes" in:

The authenticity of host '192.168.0.136 (192.168.0.136)' can't be established.
ECDSA key fingerprint is SHA256:tZiiWJJYFdtTmjjk3kunA4dU3wI2WXPI/1O0EsMtIjk.
Are you sure you want to continue connecting (yes/no/[fingerprint])?

I have tried yes | git clone ... but it is not working

Right now I am doing it this way:

echo "github.com,140.82.121.3 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==" >> /root/.ssh/known_hosts \

But the first approach would look better than having this in Dockerfile


Solution

  • You can do it in below way

    ssh-keyscan github.com >> /root/.ssh/known_hosts