Using Host SSH Key in Docker Build
2023-05-23 09:55 (2 years ago)
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
Please rate this article
Currently unrated
The author runs the application development company Cyberneura.
We look forward to discussing your development needs.
We look forward to discussing your development needs.