I believe you have two approaches here:
Copy ssh keys into the container (as suggested by Caio Augusto Papa) still in Dockerfile doing something like
COPY path/local path/no/container
For example, based on an image of Ubuntu, it would look something like
COPY ~/.ssh/SUA-CHAVE ~/.ssh/CHAVE-NO-CONTAINER
The problem I see with this approach is that this layer will stay forever in the history of the image, that is, everyone can have access to your ssh key running something like:
sudo docker history [sua-imagem:versão]
- Use the Docker Secrets that was done to pass this type of information so that it does not stay in the history layer. To adopt this approach, it will be necessary to enable the Docker build experimental. The two processes are very quiet to do just by following the documentation.
In this case, you will do a Dockerfile line with the "RUN --mount" command before copying the gitlab repository and, at the "Docker build" command, you will pass the key with the "-secret" flag".
I hope I’ve helped.