Tutorial: Docker Build & Push
In this tutorial you will build a pipeline that builds a Docker image and pushes it to Docker Hub whenever a version tag is pushed (e.g. v1.2.3).
Time: ~10 minutes Export target: GitHub Actions
Prerequisites
- A Docker Hub account
- A repository with a
Dockerfileat the root - A Docker Hub access token (create one at hub.docker.com → Account Settings → Security)
What you'll build
Trigger: tag push matching v*
│
▼
[Release Stage]
└── docker-release (ubuntu-latest)
1. Checkout
2. Docker login
3. Docker build
4. Docker push
5. Notify Slack (optional)Step 1 — Store your Docker Hub token
Before building the pipeline, save your Docker Hub token in the credential vault.
- Go to Settings → Credentials → New Credential
- Fill in:
- Label:
Docker Hub Token - Provider:
docker - Value:
<your Docker Hub access token>
- Label:
- Save
Step 2 — Create the pipeline
- Open (or create) your project
- Click New Pipeline → name it
docker-release
Step 3 — Configure the trigger
Click Trigger:
- Type: Tag
- Tag patterns:
v*
This fires on any tag that starts with v.
Step 4 — Add the Release stage
Add a stage named Release.
Double-click to enter it. Add a job:
- Name:
docker-release - Runs on:
ubuntu-latest
Enter the job and add steps:
Step 1 — Checkout
- Type:
git/ Operation:checkout
Step 2 — Docker login
- Type:
docker/ Operation:run(orshell_command) - Script:bash
echo "$DOCKER_TOKEN" | docker login -u "$DOCKER_USERNAME" --password-stdin - Secrets: select
Docker Hub Token→ it will be injected asDOCKER_TOKEN - Environment variables:
DOCKER_USERNAME=yourdockerhubusername
Step 3 — Docker build
- Type:
docker/ Operation:build - Image name:
yourusername/my-app - Tag:
${ { github.ref_name } }(GitHub Actions expression for the tag name) - Dockerfile:
./Dockerfile
Step 4 — Docker push
- Type:
docker/ Operation:push - Image:
yourusername/my-app:${ { github.ref_name } }
Step 5 — Also push latest tag (optional)
- Type:
shell_command - Script:bash
docker tag yourusername/my-app:${ { github.ref_name } } yourusername/my-app:latest docker push yourusername/my-app:latest
Step 5 — Save and export
Click Save then Export → GitHub Actions → Download.
Commit docker-release.yml to .github/workflows/.
Step 6 — Test the pipeline
Push a tag:
git tag v1.0.0
git push origin v1.0.0GitHub Actions will trigger, build your image, and push yourusername/my-app:v1.0.0 and yourusername/my-app:latest to Docker Hub.
Add a Slack notification (optional)
At the end of the job, add a notification step to announce the release:
Step — Notify Slack
- Type:
notification - Channel:
slack - Webhook URL: stored as a credential named
Slack Webhook - Message:
🚀 Released yourusername/my-app:${ { github.ref_name } }
