Add an SSH key to Velocity

If your container image includes dependencies that require an SSH key to be added at build time, you can facilitate that process within Velocity by adding your SSH key(s) as build arguments via the Velocity Wizard or the edit area for configurations that you've already created.

Adding SSH keys to container images

The established best practice for including a local SSH key in a container is to use your local SSH Agent to inject the key at buildtime, so that the key itself won't be present in the final, built image as a security measure.

SSH Agent

A background process on your machine that manages SSH keys.You can confirm that your SSH agent is running, or start it if it isn't running, with the following command:

eval "$(ssh-agent -s)"

You can then add an existing, local SSH key to the agent with the following command:ssh-add /path/to/your/private-key

Dockerfile syntax

With the above in place, you can then add a SSH key to your container image via the SSH agent with the following syntax:

# Dockerfile
# Add your SSH key using --mount=type=ssh
RUN --mount=type=ssh,id=sshkey git clone /app

Local Docker build command

Then, to add the default SSH key from your local SSH agent during a local build, you'll need to include the following in your docker build command:

docker build ... --ssh=default ...

Adding a SSH key to a Velocity-built image

Adding multiple SSH keys to a Velocity-built image

To add multiple SSH keys into a Velocity-built image, you can use the Build Args table provided in the Run Configuration Wizard, as follows:

Last updated