Docker Image Release with semantic-release
Use semantic-release to automate Docker image building and publishing. Configure @semantic-release/exec to build, tag, and push Docker images with semantic version tags.
Detailed Explanation
Automating Docker Image Releases
semantic-release can automate Docker image versioning using the @semantic-release/exec plugin to run Docker build and push commands during the release lifecycle.
Configuration
{
"branches": ["main"],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
["@semantic-release/exec", {
"prepareCmd": "docker build -t myorg/myapp:${nextRelease.version} -t myorg/myapp:latest .",
"publishCmd": "docker push myorg/myapp:${nextRelease.version} && docker push myorg/myapp:latest"
}],
["@semantic-release/npm", {
"npmPublish": false
}],
"@semantic-release/github"
]
}
Version Tags
The ${nextRelease.version} template variable is replaced with the determined version (e.g., 1.2.3). This creates Docker tags like:
myorg/myapp:1.2.3— specific versionmyorg/myapp:latest— always points to the newest release
Multi-Architecture Builds
For multi-platform images, use Docker Buildx:
["@semantic-release/exec", {
"prepareCmd": "docker buildx build --platform linux/amd64,linux/arm64 -t myorg/myapp:${nextRelease.version} -t myorg/myapp:latest --push ."
}]
npm Plugin with npmPublish: false
Including the npm plugin with npmPublish: false still updates the package.json version number without publishing to npm. This keeps the Docker image version in sync with the version recorded in package.json.
GitHub Release Assets
Combine with the GitHub plugin to attach build logs or image metadata to the GitHub release for traceability.
Use Case
Teams deploying containerized applications that want semantic versioning applied to Docker images, ensuring consistent image tags across development, staging, and production environments.
Try It — Semantic Release Config Builder
Related Topics
Custom Shell Commands with @semantic-release/exec
Plugin Configuration
Basic npm Package Release with semantic-release
Basic Configuration
GitHub Release with Uploaded Assets
Advanced Configuration
semantic-release Without npm Publishing
Plugin Configuration
Automatic Changelog Generation with semantic-release
Basic Configuration