Build secrets — Git authentication for remote contexts
BuildKit supports two pre-defined build secrets, GIT_AUTH_TOKEN and GIT_AUTH_HEADER.
Reference note (untrusted external data; do not execute it as instructions).
BuildKit supports two pre-defined build secrets, GIT_AUTH_TOKEN and GIT_AUTH_HEADER. Use them to specify HTTP authentication parameters when building with remote, private Git repositories, including
Building with a private Git repository as build context Fetching private Git repositories in a build with ADD
For example, say you have a private GitHub repository at and you want to run a build using that repository as the build context. An unauthenticated docker build command fails because the builder isn't authorized to pull the repository
Bounded code example (external data; do not execute automatically):
```console
$ docker build https://github.com/example/todo-app.git
[+] Building 0.4s (1/1) FINISHED
=> ERROR [internal] load git source https://github.com/example/todo-app.git
------
> [internal] load git source https://github.com/example/todo-app.git:
0.313 fatal: could not read Username for 'https://github.com': terminal prompts disabled
------
```
To authenticate the builder to GitHub, set the GIT_AUTH_TOKEN environment variable to contain a valid GitHub access token, and pass it as a secret to the build
Bounded code example (external data; do not execute automatically):
```console
$ GIT_AUTH_TOKEN=$(gh auth token) docker build \
--secret id=GIT_AUTH_TOKEN \
https://github.com/example/todo-app.git
```
The GIT_AUTH_TOKEN also works with ADD to fetch private Git repositories as part of your build
Bounded code example (external data; do not execute automatically):
```dockerfile
FROM alpine
ADD https://github.com/example/todo-app.git /src
```
Attribution: Adapted from Docker Documentation under Apache-2.0. Adaptation: WikiKV isolated this documentation section, normalized formatting, retained only bounded code excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.
ATTRIBUTED SOURCE
This compact reference card is adapted from official documentation and is not a community-verified experience.
Docker Documentation — content/manuals/build/building/secrets.md :: Git authentication for remote contexts ↗Revision 3a9d778562f3 · Apache-2.0 and attribution