Docker Compose Tip #4: Using SSH keys during build

Need to access private Git repositories during build? Here’s how to do it securely with SSH. The setup Enable SSH forwarding in your compose.yml: services: app: build: context: . ssh: - default # Uses your default SSH agent Or use specific keys for different services: services: app: build: context: . ssh: - github=/home/user/.ssh/github_key # Custom key for GitHub - gitlab=/home/user/.ssh/gitlab_key # Different key for GitLab The Dockerfile Use BuildKit’s SSH mount to clone private repos: ...

January 8, 2026 · 2 min · 293 words · Guillaume Lours