Dockerfile generator for .NET 8+ apps
$ dotnet add package dockgendock-gen is a simple .NET tool designed to generate Dockerfiles for one or multiple projects in a solution based on project dependencies.
Please note, dock-gen is still in its early stages, some features may not be stable.
To install dock-gen, you can use the dotnet tool install command:
a) global installation:
dotnet tool install --global dockgen
b) local installation: (optional) if you don't have a manifest file for your project, create one:
dotnet new tool-manifest
Add the tool to the manifest file:
dotnet tool install dockgen
| Command | Aliases | Description |
|---|---|---|
generate | g, gen | Generate Dockerfiles for eligible projects discovered from --solution or --directory, or for a single project specified via --project. |
update | u, upd | Update Dockerfiles for eligible projects discovered from --solution or --directory, or for a single project specified via --project. By default rewrites the whole file; with --only-references updates only the project-reference COPY section inside the build stage and leaves the rest untouched. |
| Option | Aliases | Type | Default | Description |
|---|---|---|---|---|
--verbose | --debug, --trace | bool | false | Enable detailed logging (includes trace output). Use before the command name. |
g, gen)| Option | Aliases | Type | Default | Description |
|---|---|---|---|---|
--directory | -d | string | Discover projects under a directory (recursively) and generate Dockerfiles for eligible projects. | |
--solution | -s | string | Discover projects in a solution and generate Dockerfiles for eligible projects. | |
--project | -p | string | Generate a Dockerfile for a single project. | |
--analyzer | -a | string | FastAnalyzer | Analyzer to use: FastAnalyzer, DesignBuildTimeAnalyzer, SimpleAnalyzer. |
--multi-arch | bool | true | Generate a multi-arch Dockerfile (FROM --platform=$BUILDPLATFORM). |
If none of --solution, --project, or --directory are provided, dock-gen will try to locate all projects inside the current directory recursively.
u, upd)| Option | Aliases | Type | Default | Description |
|---|---|---|---|---|
--directory | -d | string | Discover projects under a directory (recursively) and update Dockerfiles for eligible projects. | |
--solution | -s | string | Discover projects in a solution and update Dockerfiles for eligible projects. | |
--project | -p | string | Update the Dockerfile for a single project. | |
--analyzer | -a | string | FastAnalyzer | Analyzer to use: FastAnalyzer, DesignBuildTimeAnalyzer, SimpleAnalyzer. |
--multi-arch | bool | true | Generate a multi-arch Dockerfile (FROM --platform=$BUILDPLATFORM). | |
--only-references | bool | false | Update only the project-reference COPY section in the existing Dockerfile. |
If none of --solution, --project, or --directory are provided, dock-gen will try to locate all projects inside the current directory recursively.
Generate Dockerfiles for all projects in a solution:
dotnet dockgen generate --solution .\\Solution.sln
Generate Dockerfiles (using alias):
dotnet dockgen g --solution .\\Solution.sln
Update Dockerfiles for all projects in a solution:
dotnet dockgen update --solution .\\Solution.sln
Update only the project reference COPY section in existing Dockerfiles:
dotnet dockgen update --solution .\\Solution.sln --only-references
Enable detailed logging (any of these is equivalent):
dotnet dockgen --verbose g --solution .\\Solution.sln
Use a non-default analyzer:
dotnet dockgen generate --analyzer DesignBuildTimeAnalyzer --solution .\\Solution.sln
FastAnalyzer does not run MSBuild. It can’t evaluate all conditional logic, custom tasks, or target execution.
If your repo relies heavily on dynamic MSBuild evaluation, prefer DesignBuildTimeAnalyzer.Description for MSBuild properties can be found here: Official .NET docs
| Property | Description | MSBuild Property | Custom Property | Default Value |
|---|---|---|---|---|
| ContainerBaseImage* | ✔ yes | ✘ no | mcr.microsoft.com:443/dotnet/aspnet:10.0 | |
| ContainerRegistry | Registry of the base image | ✔ yes | ✘ no | mcr.microsoft.com |
| ContainerRepository | Repository of the base image | ✔ yes | ✘ no | dotnet/aspnet |
| ContainerFamily | Family of the base image | ✔ yes | ✘ no | |
| ContainerImageTag | Tag of the base image | ✔ yes | ✘ no | 10.0 |
| ContainerBasePort | Port of the base image | ✘ no | ✔ yes | 443 |
| ContainerPort | Port(s) to expose in Dockerfile | ✔ yes | ✘ no | |
| ContainerBuildImage | Build image for the project | ✘ no | ✔ yes | mcr.microsoft.com:443/dotnet/sdk:10.0 |
| ContainerBuildRegistry | Registry of the build image | ✘ no | ✔ yes | mcr.microsoft.com |
| ContainerBuildRepository | Repository of the build image | ✘ no | ✔ yes | dotnet/sdk |
| ContainerBuildFamily | Family of the build image | ✘ no | ✔ yes | |
| ContainerBuildImageTag | Tag of the build image | ✘ no | ✔ yes | 10.0 |
| ContainerBuildPort | Port of the build image | ✘ no | ✔ yes | 443 |
We welcome contributions to dock-gen!
dock-gen is open source software licensed under the MIT. See the LICENSE file for more details.
If you have any questions or feedback, please feel free to create an issue.
Dockerfile not generated
OutputType=Exe) get Dockerfiles. Library projects are skipped.Dependency graph looks incomplete
--analyzer DesignBuildTimeAnalyzer to use MSBuild design-time evaluation.This project makes use of the following open source projects: