dock-gen is a very simple .NET tool designed to generate Dockerfiles for one or multiple projects in a solution based on dependencies in a predictable way each time.
Please note, dock-gen is still in its early stages, some features may not be stable.
Since .NET 7, dotnet comes with a built-in feature to publish app as container image. If you don't need to generate Dockerfiles, you can use the
dotnet publishcommand to publish your application as container. For more information, see the official documentation. dock-gen is designed to provide more control over the Dockerfile generation process but it may not be suitable for all use cases.
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 dockgenYou can use dock-gen with the generate command.
You can provide these options to tell dock-gen where to find projects or solutions:
--solution (-s) : path to a solution file
--project (-p) : path to a project file
--directory (-d) : path to a directoryif none of these options are provided, dock-gen will try to locate all projects inside the current directory recursively.
Additional options:
--analyzer (-a) : which analyzer to use to evaluate project (SimpleAnalyzer | DesignTimeBuildAnalyzer (default))
SimpleAnalyzer - plain text parsing of project file
DesignTimeBuildAnalyzer - uses Buildalyzer to analyze project, much slower but can extract more information and more reliable
--multi-arch : generate multi-arch Dockerfile (default: true)Here is an example of how to use the generate command:
dotnet dockgen generate --analyzer SimpleAnalyzer --solution .\Solution.slnxIf no solution or project file is specified, dock-gen will try to find a solution file in the current directory.
- 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:8.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 | 8.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:8.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 | 8.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.
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