Docker and how to add the SSH key to a container

Sometimes we need to build a container and install a library from a private repository

Image by congerdesign from Pixabay

TL;DR

We will send SSH private key using --build-arg then write it to id_ed25519 or id_rsa file in the container.

Dockerfile (the important part)

# Add ssh private key into container
ARG SSH_PRIVATE_KEY
RUN mkdir…