Overview
The Intent.AspNetCore.Docker module installs Docker support into your ASP.NET Core application, similar to how Visual Studio would if you select “Enable Docker support” on solution creation. This module generates production-ready Dockerfiles with multi-stage builds optimized for .NET applications, along with.dockerignore files and debugging configurations.
What Gets Generated
Dockerfile
A multi-stage Dockerfile optimized for ASP.NET Core applications:YourApi/Dockerfile
.dockerignore
A.dockerignore file to exclude unnecessary files from the Docker build context:
.dockerignore
Visual Studio Integration
When using Visual Studio, the module configures:- Debug targets for Docker
- Fast mode debugging support
- Docker Compose integration (if applicable)
Installation
Prerequisites
- An ASP.NET Core application in Intent Architect
- Docker Desktop installed on your development machine
Installation Steps
Install Docker Desktop
Download and install Docker Desktop for your operating system.
Install the module
In Intent Architect, right-click on your application and select Manage Modules. Search for
Intent.AspNetCore.Docker and install it.Usage
Running in Visual Studio
The easiest way to run or debug your application under Docker in Visual Studio:- Open your solution in Visual Studio
- Select Docker from the Debug Target dropdown
- Press F5 to start debugging
Visual Studio will:
- Build your Docker image
- Start a container
- Attach the debugger
- Open your browser to the application URL
Building with Docker CLI
From a terminal in the folder of the project with the entry point of your application:-fspecifies the Dockerfile to use-tspecifies the docker image name and tag..at the end specifies the build context (parent directory)
The build context should be the solution root directory (one level up from the project folder) to ensure all project references can be resolved.
Running with Docker CLI
-pmaps host port 8080 to container port 8080- Use
-Pto publish all exposed ports to random ports
Configuration
Environment Variables
ASP.NET Core applications can be configured usingappsettings.json and environment variables.
Hierarchy
Configuration sources are applied in this order (later sources override earlier ones):- appsettings.json - Base configuration
- appsettings..json - Environment-specific overrides
- Environment Variables - Runtime configuration
- Command-line arguments - Highest priority
Setting Environment Variables
Pass via command-line arguments:Use double underscores
__ to represent nested configuration sections. For example, ConnectionStrings__DefaultConnection maps to ConnectionStrings:DefaultConnection in appsettings.json..env file:
.env
Example Configuration Override
appsettings.json:appsettings.json.
Docker Compose
For applications with multiple services (API, database, cache), consider using Docker Compose:docker-compose.yml
Best Practices
Multi-Stage Builds
The generated Dockerfile uses multi-stage builds to minimize final image size by excluding build tools.
Use .dockerignore
Keep your build context small by excluding unnecessary files like
bin, obj, and .git.Non-Root User
The container runs as a non-root user (
$APP_UID) for improved security.Environment-Specific Config
Use environment variables for sensitive data instead of hardcoding in
appsettings.json.Security Considerations
- Never commit secrets to version control
- Use environment variables for connection strings and API keys
- Scan images for vulnerabilities regularly
- Keep base images updated to receive security patches
Performance Optimization
Troubleshooting
Clear Visual Studio Docker Cache
There are scenarios where you need to clear out your local.vs folder:
- When changing your development hosting option (from Docker to Local Kestrel or vice versa)
- To regenerate the Docker certificate setup when running the dockerized solution
- When experiencing connection issues during debugging
- Close Visual Studio
- Delete the
.vsfolder in your solution directory - Restart Visual Studio
Common Issues
Issue: Container can’t connect to host SQL Server Solution: Usehost.docker.internal instead of localhost in connection strings:
Integration with Other Modules
Azure Pipelines
Build and push Docker images in CI/CD pipelines.
OpenTelemetry
Monitor containerized applications with distributed tracing.
Serilog
Structured logging works seamlessly in containers.
Health Checks
Container orchestrators use health checks for readiness probes.
Related Resources
Next Steps
Azure Pipelines
Automate Docker builds in CI/CD
Kubernetes
Deploy containers to Kubernetes
Monitoring
Add observability to containers
