3

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

Jakub Znamenáček
  • 766
  • 1
  • 4
  • 18

2 Answers2

4

You can do it in below way

ssh-keyscan github.com >> /root/.ssh/known_hosts
Tarun Lalwani
  • 142,312
  • 9
  • 204
  • 265
0

You can get the fingerprint as a new file and create a volume that maps this file, before the container starts.

  1. Get the fingerprint
ssh-keyscan github.com >> [MY_DOCKER_PROJECT]/.ssh/known_hosts
  1. Add to docker-compose.yml:
    volumes:
      - ./ssh/known_hosts:/root/.ssh/known_hosts
rodrigomelo
  • 59
  • 1
  • 1
  • 3