A dotnet new template package that scaffolds a production-ready .NET background worker service in Docker, including GitHub Actions workflows for CI and container publishing.
Install from NuGet:
dotnet new install Rafatz.DotnetDockerWorkerUninstall:
dotnet new uninstall Rafatz.DotnetDockerWorkerdotnet new dotnet-docker-worker \
--DotnetName "Acme.DataSync" \
--GithubOwner "acme-corp" \
--GithubName "data-sync-worker"| Parameter | Description | Default |
|---|---|---|
--DotnetName |
Full .NET root namespace and project name prefix | Company.ProjectName |
--GithubOwner |
GitHub username or organization | github-owner |
--GithubName |
GitHub repository name in kebab-case | project-name |
DotnetShortName is generated from the last segment of DotnetName and used in class names and file renames.
- .NET 10 worker service using
BackgroundService - Fail-fast config binding for
WORKER_DELAY - Structured JSON console logging (
AddJsonConsole) - Multi-stage Dockerfile (SDK build image + runtime image)
docker-compose.ymlprefilled with a GHCR image name- GitHub Actions workflows:
- PR validation (
restore,build,test) - Docker image build and push to GHCR
- NuGet publish workflow (release-triggered)
- PR validation (
- xUnit test project scaffold with AutoFixture, AutoMoq, Moq, and coverlet
.slnxsolution file
Run with Docker Compose:
docker compose up -dOr run directly with .NET:
dotnet restore
dotnet build
dotnet test
dotnet run --project src/Acme.DataSync.Worker/Acme.DataSync.Worker.csprojThe worker reads configuration from environment variables:
| Variable | Description | Example |
|---|---|---|
WORKER_DELAY |
Delay between worker cycles, in minutes | 15 |
Rafatz.DotnetDockerWorker.csproj: template package projectREADME.nuget.md: NuGet package readmetemplates/dotnet-docker-worker: template source content
Pack the template locally:
dotnet pack Rafatz.DotnetDockerWorker.csproj --configuration Release --output ./nupkgInstall from the generated package:
dotnet new install ./nupkg/Rafatz.DotnetDockerWorker.1.0.0.nupkgAfter changes, reinstall by uninstalling first (or use a newer version number):
dotnet new uninstall Rafatz.DotnetDockerWorker
dotnet new install ./nupkg/Rafatz.DotnetDockerWorker.1.0.0.nupkgMIT