mirror of https://github.com/docker/docs.git
build(gha): move named contexts section to dedicated page
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
parent
f344c6762d
commit
e7752b350c
|
@ -1627,6 +1627,8 @@ manuals:
|
|||
title: Local registry
|
||||
- path: /build/ci/github-actions/share-image-jobs/
|
||||
title: Share built image between jobs
|
||||
- path: /build/ci/github-actions/named-contexts/
|
||||
title: Named contexts
|
||||
- path: /build/ci/github-actions/examples/
|
||||
title: Examples
|
||||
- sectiontitle: Bake
|
||||
|
|
|
@ -7,101 +7,7 @@ keywords: ci, github actions, gha, examples
|
|||
This page showcases different examples of how you can customize and use the
|
||||
Docker GitHub Actions in your CI pipelines.
|
||||
|
||||
## Named contexts
|
||||
|
||||
You can define [additional build contexts](../../../engine/reference/commandline/buildx_build.md#build-context),
|
||||
and access them in your Dockerfile with `FROM name` or `--from=name`. When
|
||||
Dockerfile defines a stage with the same name it's overwritten.
|
||||
|
||||
This can be useful with GitHub Actions to reuse results from other builds or pin
|
||||
an image to a specific tag in your workflow.
|
||||
|
||||
### Pin image to a tag
|
||||
|
||||
Replace `alpine:latest` with a pinned one:
|
||||
|
||||
```dockerfile
|
||||
# syntax=docker/dockerfile:1
|
||||
FROM alpine
|
||||
RUN echo "Hello World"
|
||||
```
|
||||
|
||||
```yaml
|
||||
name: ci
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- "main"
|
||||
|
||||
jobs:
|
||||
docker:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
-
|
||||
name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
-
|
||||
name: Build
|
||||
uses: docker/build-push-action@v4
|
||||
with:
|
||||
context: .
|
||||
build-contexts: |
|
||||
alpine=docker-image://alpine:3.16
|
||||
tags: myimage:latest
|
||||
```
|
||||
|
||||
### Use image in subsequent steps
|
||||
|
||||
By default, the [Docker Setup Buildx](https://github.com/marketplace/actions/docker-setup-buildx){:target="blank" rel="noopener" class=""}
|
||||
action uses `docker-container` as a build driver, so built Docker images aren't
|
||||
loaded automatically.
|
||||
|
||||
With named contexts you can reuse the built image:
|
||||
|
||||
```dockerfile
|
||||
# syntax=docker/dockerfile:1
|
||||
FROM alpine
|
||||
RUN echo "Hello World"
|
||||
```
|
||||
|
||||
```yaml
|
||||
name: ci
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- "main"
|
||||
|
||||
jobs:
|
||||
docker:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
-
|
||||
name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
-
|
||||
name: Build base image
|
||||
uses: docker/build-push-action@v4
|
||||
with:
|
||||
context: base
|
||||
load: true
|
||||
tags: my-base-image:latest
|
||||
-
|
||||
name: Build
|
||||
uses: docker/build-push-action@v4
|
||||
with:
|
||||
context: .
|
||||
build-contexts: |
|
||||
alpine=docker-image://my-base-image:latest
|
||||
tags: myimage:latest
|
||||
```
|
||||
|
||||
## Copy images between registries
|
||||
|
||||
|
|
|
@ -0,0 +1,102 @@
|
|||
---
|
||||
title: Named contexts with GitHub Actions
|
||||
keywords: ci, github actions, gha, buildkit, buildx, context
|
||||
---
|
||||
|
||||
You can define [additional build contexts](../../../engine/reference/commandline/buildx_build.md#build-context),
|
||||
and access them in your Dockerfile with `FROM name` or `--from=name`. When
|
||||
Dockerfile defines a stage with the same name it's overwritten.
|
||||
|
||||
This can be useful with GitHub Actions to reuse results from other builds or pin
|
||||
an image to a specific tag in your workflow.
|
||||
|
||||
## Pin image to a tag
|
||||
|
||||
Replace `alpine:latest` with a pinned one:
|
||||
|
||||
```dockerfile
|
||||
# syntax=docker/dockerfile:1
|
||||
FROM alpine
|
||||
RUN echo "Hello World"
|
||||
```
|
||||
|
||||
{% raw %}
|
||||
```yaml
|
||||
name: ci
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- "main"
|
||||
|
||||
jobs:
|
||||
docker:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
-
|
||||
name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
-
|
||||
name: Build
|
||||
uses: docker/build-push-action@v4
|
||||
with:
|
||||
context: .
|
||||
build-contexts: |
|
||||
alpine=docker-image://alpine:3.16
|
||||
tags: myimage:latest
|
||||
```
|
||||
{% endraw %}
|
||||
|
||||
## Use image in subsequent steps
|
||||
|
||||
By default, the [Docker Setup Buildx](https://github.com/marketplace/actions/docker-setup-buildx){:target="blank" rel="noopener" class=""}
|
||||
action uses `docker-container` as a build driver, so built Docker images aren't
|
||||
loaded automatically.
|
||||
|
||||
With named contexts you can reuse the built image:
|
||||
|
||||
```dockerfile
|
||||
# syntax=docker/dockerfile:1
|
||||
FROM alpine
|
||||
RUN echo "Hello World"
|
||||
```
|
||||
|
||||
{% raw %}
|
||||
```yaml
|
||||
name: ci
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- "main"
|
||||
|
||||
jobs:
|
||||
docker:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
-
|
||||
name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
-
|
||||
name: Build base image
|
||||
uses: docker/build-push-action@v4
|
||||
with:
|
||||
context: base
|
||||
load: true
|
||||
tags: my-base-image:latest
|
||||
-
|
||||
name: Build
|
||||
uses: docker/build-push-action@v4
|
||||
with:
|
||||
context: .
|
||||
build-contexts: |
|
||||
alpine=docker-image://my-base-image:latest
|
||||
tags: myimage:latest
|
||||
```
|
||||
{% endraw %}
|
Loading…
Reference in New Issue