Skip to content

Instantly share code, notes, and snippets.

@lyf2000
Created November 5, 2024 15:08
Show Gist options
  • Save lyf2000/c6e39b7de67ee0ea9f26b9eef118cf83 to your computer and use it in GitHub Desktop.
Save lyf2000/c6e39b7de67ee0ea9f26b9eef118cf83 to your computer and use it in GitHub Desktop.
docker compose build with ssh clone, install from private git repo
eval $(ssh-agent)
ssh-add ~/.ssh/id_rsa # pass own path
export COMPOSE_DOCKER_CLI_BUILD=1
export DOCKER_BUILDKIT=1
docker-compose build --ssh default=$SSH_AUTH_SOCK
# Docs: https://docs.docker.com/reference/dockerfile/#run---mounttypessh
# req.txt: pckgname @ git+ssh://[email protected]/<repo>.git@<version if need>
# in terminal:
# syntax=docker/dockerfile:1
FROM python:3.12-alpine AS build
RUN apk add --no-cache git openssh-client
RUN mkdir -p -m 0700 ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts
WORKDIR /app
COPY req.txt .
RUN --mount=type=ssh \
pip install --user -r req.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment