Dockerfile

1
2
3
4
5
6
7
8
9
...
# 共享宿主机git私钥
RUN yum install git -y && \
mkdir -p /root/.ssh/ && \
echo "${SSH_KEY}" > /root/.ssh/id_rsa && \
chmod 600 /root/.ssh/id_rsa && \
touch /root/.ssh/known_hosts && \
ssh-keyscan <gitlab_id>/github.com/gitee.com >> /root/.ssh/known_hosts
...

执行(~/.ssh/git/id_rsa是宿主机git私钥所在位置)

1
docker build -t <xxx> --build-arg SSH_KEY="$(cat ~/.ssh/git/id_rsa) .