Careeroza
CI/CD with Docker
A Typical Pipeline
- Push to Git triggers the pipeline.
- Build the image (with cache) and tag it with the commit SHA.
- Run tests inside the image.
- Scan the image for vulnerabilities.
- Push it to the registry.
- Deploy that exact tag to staging, then production.
GitHub Actions Example
name: build-and-push
on:
push:
branches: [main]
jobs:
docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- uses: docker/build-push-action@v6
with:
push: true
tags: yourname/myapi:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max