Pushing Images to Registries
Configure workflows to push your built Docker images to container registries like Docker Hub or GitHub Container Registry.
Pushing Images to Registries is a free DevOps Bootcamp lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the DevOps Bootcamp learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What are Container Registries?
A container registry is a secure online storage service for your Docker images. Think of it as a cloud drive specifically designed for your application's packages.
- They store different versions of your images.
- They make it easy to share images with others.
- They are crucial for deployment to various environments.
Why Use Registries?
Registries are essential for modern software development. They provide several key benefits:
- Image Sharing: Distribute your application images easily.
- Version Control: Store and manage different versions of your app.
- Reliable Deployment: Ensure consistent deployments across environments.
- Security: Many registries offer vulnerability scanning.
Common Registry Services
There are many container registry services available. Two popular ones you'll often encounter are:
- Docker Hub: A widely used public registry. Great for sharing public images and for personal projects.
- GitHub Container Registry (GHCR): Tightly integrated with GitHub repositories. Excellent for private images and organizations already using GitHub.
Other major cloud providers also offer their own registries, like AWS ECR or Google Container Registry.
Registry Authentication
Before you can push an image to a registry, you need to prove who you are. This process is called authentication, or 'logging in'.
You'll typically provide a username and a personal access token (PAT) or password. These credentials ensure only authorized users can push or pull images from your private repositories.
Using docker/login-action
In GitHub Actions, the best way to authenticate with most Docker-compatible registries is using the docker/login-action.
This action securely logs your workflow into the specified registry, allowing subsequent steps to push images. It takes username and password as inputs.
Pushing to Docker Hub
To push an image to Docker Hub, your workflow needs to:
- Log in: Use
docker/login-actionwith your Docker Hub username and a Personal Access Token (PAT) stored as a GitHub Secret. - Build & Push: Use
docker/build-push-actionto build your image and setpush: true. Ensure your image tag includes your Docker Hub username, e.g.,your_username/my-app:latest.
Docker Hub Workflow Example
Here's a GitHub Actions workflow example to build and push a Docker image to Docker Hub. Remember to set up DOCKER_USERNAME and DOCKER_TOKEN as GitHub Secrets in your repository.
name: Publish Docker image to Docker Hub
on:
push:
branches: [ "main" ]
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/my-app:latestPushing to GHCR
GitHub Container Registry (GHCR) offers seamless integration. Key differences for GHCR:
- Authentication: You can use the built-in
GITHUB_TOKENfor authentication. Setusername: ${{ github.actor }}andpassword: ${{ secrets.GITHUB_TOKEN }}. - Permissions: Your job needs
packages: writepermission. - Image Tagging: Images are tagged like
ghcr.io/<OWNER>/<REPOSITORY>:<TAG>.
GHCR Workflow Example
This workflow demonstrates pushing an image to GitHub Container Registry. Notice the permissions block and the image tag format.
name: Publish Docker image to GHCR
on:
push:
branches: [ "main" ]
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write # Required for GHCR
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ghcr.io/${{ github.repository }}:latestCheck Your Understanding
Let's quickly review what you've learned about pushing images to container registries.
Recap: Push Your Images!
Great job! You've learned how to push Docker images to container registries using GitHub Actions.
- Container registries store and manage your Docker images.
- Authentication is a critical first step using credentials.
docker/login-actionhelps you log in securely.- You saw examples for both Docker Hub and GitHub Container Registry, understanding their unique authentication and tagging requirements.
Next, you'll learn how to deploy these images to Kubernetes!
Frequently asked questions
Is the “Pushing Images to Registries” lesson free?
Yes — the full text of “Pushing Images to Registries” is free to read here on the web, and the DevOps Bootcamp course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the DevOps Bootcamp course, upgrade to CoddyKit PRO.
What will I learn in “Pushing Images to Registries”?
Configure workflows to push your built Docker images to container registries like Docker Hub or GitHub Container Registry. You practise DevOps Bootcamp with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start DevOps Bootcamp?
No prior experience is required. DevOps Bootcamp on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Pushing Images to Registries” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this DevOps Bootcamp lesson?
Yes. Every DevOps Bootcamp lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.