I have a suggestion myself, if it works and is legit I don't know.
On Amazon I add an environment variable SSHKEY with the base64 encoded private key. In my Dockerfile I import it by using this
RUN mkdir /root/.ssh/
RUN ssh-keyscan gitlab.com >> /root/.ssh/known_hosts
RUN echo SSHKEY | base64 --decode 2> nul > /root/.ssh/id_rsa