Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building a Docker image from a private GitHub repository with docker-compose

I know it's possible to supply a GitHub HTTP URL as a service's build context:

version: '3.9'

services:
  my-app:
    build: https://github.com/rambo/my-app.git

The above works well for public repos. But what if the Dockerfile is stored in a private repo that requires authentication (e.g. via SSH). Is something like the below example supported?

services:
  my-app:
    build: ssh://[email protected]:rambo/my-app.git

I've tried multiple variations of the above configuration but nothing seems to work.

like image 791
zepp133 Avatar asked Mar 20 '26 22:03

zepp133


2 Answers

Yes, you can achieve this by using github personal access token which have read access only https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token

And then your token is your username with empty password

Like, https://{token}@github.com/org_name/repo.git

like image 55
Vivek Bani Avatar answered Mar 22 '26 12:03

Vivek Bani


This can be done via personal access token, as described by @vivek-bani, or using SSH:

  your_service_name:
    container_name: foo-service
    build:
      dockerfile: Dockerfile-compose
      context: [email protected]:orgname/yourrproject.git#feature-branch
      ssh: [ "default" ]
    stdin_open: true
    ports:
      - "7000-7051:7000-7051"

Here, ssh: [ "default" ] indicates to docker compose that it should "mount the default ssh agent."

like image 31
chb Avatar answered Mar 22 '26 12:03

chb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!