how to specify commit in docker-compose remote github build how to specify commit in docker-compose remote github build docker docker

how to specify commit in docker-compose remote github build


As you get err ERROR: error fetching: error: no such remote ref <commit sha>: exit status 128 then most certainly you have syntax issue. In your case you have few possible causes.

  • GITHUB_ACCESS || GIT_COMMIT_SHA environment variable is not set
  • GIT_COMMIT_SHA is set to invalid sha value.

    I am certain the sha exists

    Just double check

You can configure Git URLs in their fragment section separated by a colon :. The first part represents the reference that Git will check out, this can be either a branch, a tag, or a commit SHA. So yes docker-compose does support referring to a specific commit. The second part represents a sub directory inside the repository that will be used as a build context. This is only needed when your docker file is not in repository root. Valid Git URL schemas can be anything what Git considers natively as valid. See this file found in its core for reference.

  • If your Dockerfile is not in repository root you would get ERROR: Cannot locate specified Dockerfile: Dockerfile

I'm using nginxinc/docker-nginx repository as example. There are multiple docker files in this repository, so let's say we want to build image based on Dockerfile found in repository subdirectory stable/alpine

Example 1

In this example lets build docker image from master branch

version: '3'services:  web:    image: web:latest    build: https://github.com/nginxinc/docker-nginx.git#master:stable/alpine

Example 1 - Do build it based on specific commit

I add .env file while most likely your variables are set in your Continuous Integration environment.

GIT_COMMIT_SHA=d377983a14b214fcae4b8e34357761282aca788f

and change our docker-compose.yaml to

version: '3'services:  web:    image: web:${GIT_COMMIT_SHA}    build: https://github.com/nginxinc/docker-nginx.git#${GIT_COMMIT_SHA}:stable/alpine

here resulting build: url should be https://github.com/nginxinc/docker-nginx.git#d377983a14b214fcae4b8e34357761282aca788f:stable/alpine