How to Share a Docker Image as an Artifact in GitHub Actions
docker save writes an image to a tar you can upload as an artifact, then docker load restores it in another job.
When you do not want to push to a registry, docker save the image to a tar, upload it with actions/upload-artifact@v4, and docker load it in a downstream job.
Steps
- Build the image and
docker saveit to a tar file. - Upload the tar as an artifact.
- In the next job, download it and
docker loadthe tar.
Workflow
.github/workflows/ci.yml
jobs:
build-image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: docker build -t myapp:ci .
- run: docker save myapp:ci -o image.tar
- uses: actions/upload-artifact@v4
with:
name: docker-image
path: image.tar
scan-image:
needs: build-image
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
name: docker-image
- run: docker load -i image.tar
- run: docker run --rm myapp:ci node --versionGotchas
- Saved image tars are large; use
compression-level: 0since layers are already compressed. - For anything shared long-term or across repos, a registry push beats a saved-image artifact.
Related guides
How to Upload a Large Artifact in GitHub ActionsUpload big outputs as a GitHub Actions artifact reliably by tarring first, excluding junk, and tuning compres…
How to Choose Between an Artifact and a Cache in GitHub ActionsDecide when to use actions/upload-artifact versus actions/cache in GitHub Actions: artifacts hand off build o…