Using Host SSH Key in Docker Build

2023-05-23 18:55 (1 years ago) ytyng

The Method I Used Until Now

Dockerfile

# syntax=docker/dockerfile:1.0.0-experimental
FROM python:3.10-bullseye

RUN mkdir -p -m 0600 ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts
RUN --mount=type=ssh ssh git@github.com

sh

DOCKER_BUILDKIT=1 docker build . --platform linux/amd64 --ssh default -t test-build -f Dockerfile

This Works Well

Dockerfile

FROM python:3.10-bullseye

RUN --mount=type=ssh ssh -o StrictHostKeyChecking=no git@github.com

sh

docker build . --platform linux/amd64 --ssh default -t test-build -f Dockerfile

However, if you are installing from a private git repository using pip install, you should include this:

RUN mkdir -p -m 0600 ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts
Currently unrated
The author runs the application development company Cyberneura.
We look forward to discussing your development needs.

Comments

Archive

2025
2024
2023
2022
2021
2020
2019
2018
2017
2016
2015
2014
2013
2012
2011