Registries and CI/CD
You've built great images. Now let's ship them automatically: every push to main builds, tests, scans and publishes a new image, ready to deploy. This is the core of a modern DevOps pipeline.
Container registries
A registry stores images so servers and teammates can pull them.
| Registry | Notes |
|---|---|
| Docker Hub | Default public registry |
GitHub Container Registry (ghcr.io) |
Free for public images; integrates with GitHub Actions |
| AWS ECR, Google Artifact Registry, Azure ACR | Private registries inside your cloud |
| Harbor | Self-hosted, open source |
Pushing manually
docker login ghcr.io -u YOUR_GITHUB_USERNAME # use a personal access token as the password
docker build -t ghcr.io/your-name/hello-docker:1.0.0 .
docker push ghcr.io/your-name/hello-docker:1.0.0
# on any server:
docker pull ghcr.io/your-name/hello-docker:1.0.0Tagging strategy
Good tags make deployments traceable and rollbacks easy:
| Tag | Example | Use |
|---|---|---|
| Semantic version | 1.4.2, 1.4, 1 |
Releases |
| Git commit SHA | sha-3f9c2ab |
Every build; exact traceability |
| Branch | main, staging |
Moving pointers for environments |
latest |
latest |
Convenience only; never deploy by it |
Deploy immutable tags (version or SHA). If
latestchanges under you, "redeploy the same thing" stops meaning anything.
CI/CD with GitHub Actions
Put this in .github/workflows/docker.yml in your repository:
name: Build and publish image
on:
push:
branches: [main]
tags: ["v*.*.*"]
pull_request:
permissions:
contents: read
packages: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run tests inside the build stage
run: docker build --target build -t app-test . && docker run --rm app-test npm test
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
if: github.event_name != 'pull_request'
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=sha
type=ref,event=branch
type=semver,pattern={{version}}
- uses: docker/build-push-action@v6
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Scan for vulnerabilities
uses: aquasecurity/trivy-action@0.28.0
with:
image-ref: ghcr.io/${{ github.repository }}:sha-${{ github.sha }}
severity: CRITICAL,HIGH
exit-code: "1"
if: github.event_name != 'pull_request'What this pipeline does:
- Pull requests: build and test only. Nothing is published.
- Push to
main: build, test, push tagsmainandsha-<commit>, then scan. - Git tag
v1.2.3: also publishes the1.2.3tag for a release. - Layer caching (
type=gha) makes repeat builds much faster.
Deploying the image
The final step depends on where you run containers:
| Platform | Deploy by… |
|---|---|
| Single VM | SSH in → docker compose pull && docker compose up -d |
| AWS ECS / Google Cloud Run / Azure Container Apps | Update the service to the new image tag |
| Kubernetes | kubectl set image deployment/api api=ghcr.io/…:sha-abc or GitOps (Argo CD / Flux) |
| Fly.io, Render, Railway | Point them at the image or the repo |
A simple VM deploy step:
deploy:
needs: build
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
environment: production
steps:
- uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.SERVER_HOST }}
username: deploy
key: ${{ secrets.SERVER_SSH_KEY }}
script: |
cd /srv/app
export TAG=sha-${{ github.sha }}
docker compose pull && docker compose up -d
docker image prune -fRollbacks
Because every build has an immutable SHA tag, rolling back is just redeploying the previous tag. That's no rebuild and no guessing, and it's the payoff of a good tagging strategy.
🎓 Track complete — what's next?
You now know Docker from first container to automated production pipeline. Natural next steps:
- Kubernetes: run containers across many machines with self-healing and autoscaling
- CI/CD: deeper pipelines, environments and deployment strategies (blue/green, canary)
- Cloud: run your images on AWS, GCP or Azure
- Monitoring: metrics, logs and alerts for your containers
Capstone practice
- Push your multi-stage app from earlier lessons to a GitHub repo.
- Add the workflow above and confirm an image appears under your profile's Packages.
- Make a change, push again, and verify a new
sha-…tag was published. - (Bonus) Deploy it to a free platform that runs container images and set up automatic deploys.
1.Why tag images with the git commit SHA?
2.In the workflow above, what happens on a pull request?