dock-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 dockgenb) local installation: (optional) if you don't have a manifest file for your project, create one:
dotnet new tool-manifestAdd 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. |
| 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.
| 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.slnGenerate Dockerfiles (using alias):
dotnet dockgen g --solution .\\Solution.slnUpdate Dockerfiles for all projects in a solution:
dotnet dockgen update --solution .\\Solution.slnUpdate only the project reference COPY section in existing Dockerfiles:
dotnet dockgen update --solution .\\Solution.sln --only-referencesEnable detailed logging (any of these is equivalent):
dotnet dockgen --verbose g --solution .\\Solution.slnUse a non-default analyzer:
dotnet dockgen generate --analyzer DesignBuildTimeAnalyzer --solution .\\Solution.slnFastAnalyzerdoes not run MSBuild. It can’t evaluate all conditional logic, custom tasks, or target execution. If your repo relies heavily on dynamic MSBuild evaluation, preferDesignBuildTimeAnalyzer.
- Generate Dockerfile: Generate a Dockerfile for a single or multiple projects at once
- Multi-Stage Build: Generate a multi-stage Dockerfile for a project
- Central Package/Build Management: dock-gen supports CPM/CBM in your project
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 |
- Support more advanced Dockerfile customizations
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
- Only executable projects (
OutputType=Exe) get Dockerfiles. Library projects are skipped. - Test projects are skipped.
- Only executable projects (
-
Dependency graph looks incomplete
- Try
--analyzer DesignBuildTimeAnalyzerto use MSBuild design-time evaluation.
- Try
This project makes use of the following open source projects:
- Buildalyzer: A utility for performing design-time builds of .NET projects to obtain information such as package references and compiler flags.
- Serilog: Simple .NET logging with fully-structured events.
- .NET: .NET platform