Pushing to a Registry (CD)
Once your image is built and tested, you deploy it by pushing it to a Container Registry (like Docker Hub, AWS ECR, or GitHub Container Registry - GHCR).
Authentication
Before you can push, you must log in. Use secrets to handle the credentials.
jobs:
push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and Push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: myusername/myapp:latest
This completes a full CI/CD pipeline: Code is pushed -> Tests are run -> If successful, Docker image is built -> Image is deployed to registry!
booting...