我如何执行一个命令(即运行)映像,它只是(本地)构建缓存的一部分(在GHA中),并且没有被推送到注册表中?
这里的完整示例:https://github.com/geoHeil/containerfun
Dockerfile:
FROM ubuntu:latest as builder
RUN echo hello >> asdf.txt
FROM builder as app
RUN cat asdf.txtci.yaml GHA工作流:
name: ci
on:
push:
branches:
- main
jobs:
testing:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: cache base builder
uses: docker/build-push-action@v3
with:
push: True
tags: ghcr.io/geoheil/containerfun-cache:latest
target: builder
cache-from: type=gha
cache-to: type=gha,mode=max
- name: build app image (not pushed)
run: docker buildx build --cache-from type=gha --target app --tag ghcr.io/geoheil/containerfun-app:latest .
- name: run some command in image
run: docker run ghcr.io/geoheil/containerfun-app:latest ls /
- name: one some other command in image
run: docker run ghcr.io/geoheil/containerfun-app:latest cat /asdf.txt当使用推送图像时:
docker run ghcr.io/geoheil/containerfun-cache:latest cat /asdf.txt效果很好。当使用非推送(仅缓存一个)对接程序时,会出现以下故障:
docker run ghcr.io/geoheil/containerfun-app:latest cat /asdf.txt失败与
Unable to find image 'ghcr.io/geoheil/containerfun-app:latest' locally为什么会失败?图像不应该至少驻留在本地构建缓存中吗?
编辑
显然:
- name: fooasdf
#run: docker buildx build --cache-from type=gha --target app --tag ghcr.io/geoheil/containerfun-app:latest --build-arg BUILDKIT_INLINE_CACHE=1 .
uses: docker/build-push-action@v3
with:
push: True
tags: ghcr.io/geoheil/containerfun-app:latest
target: app
cache-from: ghcr.io/geoheil/containerfun-cache:latest是一种潜在的解决办法,docker run ghcr.io/geoheil/containerfun-app:latest cat /asdf.txt现在工作得很好。然而:
cache
type=gha将内部构建器映像推送到注册表(我不是want)
之前的步骤中构建的)。
发布于 2022-08-25 09:14:04
它失败了,因为现在您使用buildx构建映像,并且它只能在buildx上下文中使用。如果您必须在docker上下文中使用该映像,则在使用buildx构建映像时,必须使用参数--load将该映像加载到对接端。请参阅https://docs.docker.com/engine/reference/commandline/buildx_build/#load
因此,将步骤改为如下所示
- name: build app image (not pushed)
run: docker buildx build --cache-from type=gha --target app --load --tag ghcr.io/geoheil/containerfun-app:latest .注意:--load参数不支持多重arch构建atm。
https://stackoverflow.com/questions/73484162
复制相似问题