0

I have a shell script that contains git clone command. This shell script is running in a docker container. How to write the Dockerfile so that git clone command can be run successfully. My current version as below:

RUN apk update; \
apk upgrade; \
apk add --no-cache \
git \
openssh \
openssh-client \
bash \
ca-certificates \
; 

RUN --mount=type=ssh set -e -x; \
    mkdir -p -m 0777 ~/.ssh; \
    printf "Host github.com\n  User git" > ~/.ssh/config; \
    ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts; \
    git config --global url."git@github.com:".insteadOf "https://github.com/"; \
    echo "Host github.com\n\tStrictHostKeyChecking no\n" >> /root/.ssh/config;

And I got the following error:

git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
  • You should not use `ssh-keyscan` to add the GitHub host keys because that doesn't verify the host keys are correct. Instead, pull the keys [from the API](https://api.github.com/meta) or just hard-code them in your Dockerfile. – bk2204 Oct 13 '22 at 00:54

0 Answers0