AI Hints
Home›CI/CD with GitHub Actions Tutorial›Versions and Releases
CI/CD with GitHub Actions · Lesson 83 of 138

Pushing to a Registry

Sharing images.

⏱ 2 min read▶ Video at 1:36:00🎓 Free
Watch this lesson in the CI/CD with GitHub Actions courseWatch on YouTube ↗Full CI/CD with GitHub Actions course

An image on the CI machine disappears when the job ends. To deploy it, you push it to a registry. That's a server that stores images, like Docker Hub, or GitHub's own container registry.

Pushing to a Registry
From the video: Pushing to a Registry
  • Images vanish after the job
  • Push to a registry
  • Docker Hub, GHCR

Login and push

The job needs permission to write packages. The login action signs in to GHCR, the GitHub container registry, using the built in GitHub token, so no extra secret is needed. Then build push action builds the image, and push true sends it to the registry, with the SHA tag.

.github/workflows/image.ymlyaml
jobs:
  image:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write
    steps:
      - uses: actions/checkout@v4
      - uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - uses: docker/build-push-action@v6
        with:
          push: true
          tags: ghcr.io/sam/shop:sha-${{ github.sha }}

Registries

GHCR is easy, because it uses GitHub's token. Docker Hub needs a username and an access token, stored as secrets. And cloud registries, like Amazon ECR, Google Artifact Registry, and Azure's registry, sit close to your servers, and usually use OIDC to log in.

keyvalue
ghcr.ioGITHUB_TOKEN
Docker Hubaccess token secret
ECR, GAR, ACRcloud, often OIDC
Only on mainnot on every PR

Summary

Log in with the login action, then build and push. Push only from trusted branches, like main. Next, publishing releases from tags.

Key takeaways
  • packages: write
  • docker/login-action
  • push: true
Next up: Releases on Tags — one tag, one release