A containerized .NET solution demonstrating Docker deployment for .NET applications including a Web API and Azure Functions.
- DotNetApi: Main ASP.NET Core Web API project
- WebApiDb: Database access library
- TestTimer: Azure Functions project with timer functionality
- .NET 8.0 SDK
- Docker
- Docker Compose
- PowerShell 5.1+
- Clone the repository
- Configure the build arguments (see Configuration section)
- Run the build script:
.\build-and-run.ps1
Create a .build-args
file in the root directory (based on .build-args.example
) with the following options:
USE_CACHE=true
PUSH_TO_REGISTRY=false
REGISTRY_URL=myregistry.azurecr.io
REGISTRY_USERNAME=username
REGISTRY_PASSWORD=password
USE_UNIQUE_SUFFIX=false
SUFFIX_TYPE=timestamp
BUILD_NUMBER=1001
Option | Description | Values |
---|---|---|
USE_CACHE |
Whether to use Docker build cache | true /false |
PUSH_TO_REGISTRY |
Push images to container registry | true /false |
REGISTRY_URL |
Container registry URL | e.g., myregistry.azurecr.io |
REGISTRY_USERNAME |
Registry username | Your username |
REGISTRY_PASSWORD |
Registry password | Your password |
USE_UNIQUE_SUFFIX |
Add unique suffix to image tags | true /false |
SUFFIX_TYPE |
Type of unique suffix | timestamp , date , or buildnum |
BUILD_NUMBER |
Build number to use with buildnum suffix type |
Any numeric value |
Environment variables should be defined in the .env
file for the DotNetApi project (see .env.example
).
The build-and-run.ps1
script handles the following:
- Reads configuration from
.build-args
- Builds Docker images using docker-compose
- Applies unique suffixes to image tags if configured
- Deploys containers locally using docker-compose
- Optionally pushes images to a container registry
# Basic usage
.\build-and-run.ps1
# To see detailed output
.\build-and-run.ps1 -Verbose
To add additional projects to the solution:
cd DotNetApi
dotnet sln DotNetApi.sln add ..\NewProject\NewProject.csproj
- If the script fails, check Docker is running
- Verify the
.build-args
file exists and has correct formatting - Ensure proper network connectivity for registry pushing
- Check
.env
file for any required environment variables
This project is licensed under the MIT License.