This guide explains how to configure your GitHub repository to automatically build and publish the Docker image.
- A GitHub account
- A GitHub repository containing this project
- Git installed locally
If not already done, create a GitHub repository and push your code:
# Initialize the git repository
git init
# Add all files
git add .
# Create the first commit
git commit -m "Initial commit: Database backup container"
# Add your GitHub repository as a remote
git remote add origin https://github.com/greite/database-backup.git
# Push to GitHub
git branch -M main
git push -u origin main- Go to your GitHub repository in a browser
- Click the Actions tab
- You should see the "Build and Push Docker Image" workflow running or completed
- Click on it to view the build details
The workflow triggers automatically when you push to the main branch.
- On your GitHub repository, go to the Packages tab (in the right-side navigation bar)
- You should see a package named after your repository
- Click on it to view details and available tags
By default, the image is private. To make it public:
- Go to the package page:
https://github.com/users/greite/packages/container/database-backup/settings - Scroll down to the "Danger Zone" section
- Click "Change visibility"
- Select "Public"
- Confirm by typing the package name
For a public image:
docker pull ghcr.io/greite/database-backup:latestFor a private image, you must authenticate first:
# Create a Personal Access Token (classic) with the 'read:packages' scope
# Go to: https://github.com/settings/tokens
# Authenticate
echo "YOUR_TOKEN" | docker login ghcr.io -u greite --password-stdin
# Then pull the image
docker pull ghcr.io/greite/database-backup:latestUpdate your compose.yml to use the pre-built image:
services:
db-backup:
image: ghcr.io/greite/database-backup:latest
# ... rest of the configurationTo create a tagged version (e.g., v1.0.0):
# Create an annotated tag
git tag -a v1.0.0 -m "Release version 1.0.0"
# Push the tag to GitHub
git push origin v1.0.0This will automatically trigger the workflow and create the following Docker tags:
ghcr.io/greite/database-backup:latestghcr.io/greite/database-backup:v1.0.0ghcr.io/greite/database-backup:1.0ghcr.io/greite/database-backup:1
Triggered on version tags (v*.*.*) or manual dispatch. Builds and pushes a multi-architecture Docker image with semantic versioning tags.
Runs 4 times daily (00:00, 06:00, 12:00, 18:00 UTC) to detect updates to the debian:trixie-slim base image. If a new version is found, the image is automatically rebuilt and pushed to keep it up to date with the latest security patches.
The release workflow automatically creates multiple tags:
| Event | Tags Created |
|---|---|
Tag v1.2.3 |
v1.2.3, 1.2, 1, latest |
| Base image update | latest |
To use Docker Hub instead of ghcr.io, edit .github/workflows/docker-build.yml:
env:
REGISTRY: docker.io
IMAGE_NAME: greite/database-backupAnd add your Docker Hub credentials to GitHub secrets:
- Go to Settings > Secrets and variables > Actions
- Add
DOCKERHUB_USERNAMEandDOCKERHUB_TOKEN - Update the login step:
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}To build only for amd64 (faster), change:
platforms: linux/amd64 # Remove linux/arm64- Check the logs in the Actions tab
- Ensure permissions are correct in
.github/workflows/docker-build.yml - Verify the Dockerfile is valid:
docker build -t test .
- Verify the workflow ran successfully
- Make sure you're logged into the correct GitHub account
- Private images are only visible to repository members
- Create a Personal Access Token with the
read:packagesscope - Authenticate:
echo "TOKEN" | docker login ghcr.io -u USERNAME --password-stdin - Try the pull again