Bradley Kirton's Blog

Published on May 31, 2024

Go home

Installing Python packages from private repos within Docker

This snippet will install a Python package from a private github repository without exposing your ssh-keys. Before you get started make sure you have the docker buildx plugin installed.

# Assuming requests were private


FROM python:3.11.6-slim-bullseye

# Git and ssh are required
RUN apt-get update && apt-get install -y ssh git


RUN mkdir -p -m 0700 ~/.ssh && ssh-keyscan >> ~/.ssh/known_hosts
RUN pip install -U pip==24.0 wheel==0.43.0
RUN python -m venv .venv
RUN --mount=type=ssh .venv/bin/python -m pip install -r
docker build --ssh default=$HOME/.ssh/id_rsa -t my-tag .