Docker provides a consistent, isolated environment for building applications. By integrating Dotfuscator into your Docker image, you can automatically protect your assemblies as part of your containerized build process.
PreEmptive does not provide pre-built Docker images for Dotfuscator. Instead, you can create your own image using the Dotfuscator Professional NuGet package.
Before You Begin
Before building a Docker image, make sure you have:
- Docker installed.
- The PreEmptive.Protection.Dotfuscator.Pro NuGet package.
- A valid Floating License.
- A Dotfuscator configuration file.
Create a Docker Image
Create a Dockerfile that installs the Dotfuscator NuGet package and configures the command-line interface.
Replace {x.y[.z]} with the appropriate Dotfuscator version.
FROM mcr.microsoft.com/dotnet/sdk:8.0
# Copy Dotfuscator to the image
COPY PreEmptive.Protection.Dotfuscator.Pro.{X.Y.Z}.nupkg .
# Install zip and extract Dotfuscator
RUN apt-get update && \
apt-get install -y zip && \
mkdir -p /opt/local/PreEmptive.Protection.Dotfuscator.Pro && \
unzip PreEmptive.Protection.Dotfuscator.Pro.{X.Y.Z}.nupkg -d /opt/local/PreEmptive.Protection.Dotfuscator.Pro
# Set up to run the command line interface
ENTRYPOINT ["dotnet", "/opt/local/PreEmptive.Protection.Dotfuscator.Pro/tools/programdir/netcore/dotfuscator.dll"]Build the Image
After creating the Dockerfile:
- Save the Dockerfile.
- Go to Dotfuscator Downloads.
- Download the appropriate PreEmptive.Protection.Dotfuscator.Pro.{x.y.z}.nupkg package.
- Place the NuGet package in the same directory as the Dockerfile.
- Build the image.
Example:
docker build -t preemptive/dotfuscator:{x.y.z} {path-to-dockerfile-directory}Run the Container
When running the container, provide your Dotfuscator license and mount the project directory that contains your Dotfuscator configuration file.
Dotfuscator supports several methods for providing the license.
Mirrored from the current environment:
docker run --rm -e DOTFUSCATOR_LICENSE -v {projectPath}:/code preemptive/dotfuscator:{x.y.z} /code/dotfuscatorconfig.xmlSet in the container’s environment:
docker run --rm -e DOTFUSCATOR_LICENSE={LicenseString} -v {projectPath}:/code preemptive/dotfuscaator:{x.y.z} /code/dotfuscatorconfig.xmlPassed via the command line:
docker run --rm -v {projectPath}:/code preemptive/dotfuscator:{x.y.z} -license:<license-string> /code/dotfuscatorconfig.xmlFor additional command-line options, see Command Line Reference.
Troubleshooting Restricted or Offline Environments
If your Docker environment has restricted or no internet access, you can provide the required tools using one of the following approaches.
Option 1: Include the Tools in the Docker Image
This approach copies ILASM and ILDASM into the Docker image during the build.
Dockerfile script:
#Create a directory for the tools inside the container
RUN mkdir -p /usr/local/tools
#Copy tools from the host to the container
#Ensure ilasm and ildasm are placed within the build context of the Dockerfile
COPY ilasm /usr/local/tools/ilasm
COPY ildasm /usr/local/tools/ildasm
#Make the tools executable
RUN chmod +x /usr/local/tools/ilasm /usr/local/tools/ildasm
#Set environment variables for Dotfuscator to locate the tools
ENV ILASM_PATH=/usr/local/tools/ilasm
ENV ILDASM_PATH=/usr/local/tools/ildasm
#Copy Dotfuscator and its configuration into the container
COPY /path/to/dotfuscator /usr/local/dotfuscator
COPY /path/to/dotfuscatorconfig.xml /usr/local/dotfuscator/dotfuscatorconfig.xml
#Define the default command to run Dotfuscator with the provided configuration
#Adjust the command as needed to execute Dotfuscator
#For example : CMD ["dotfuscator", "/usr/local/dotfuscator/dotfuscatorconfig.xml"]Use this approach when you want all required tools packaged inside the Docker image.
Option 2: Mount the Tools at Runtime
Instead of copying the tools into the image, mount them as Docker volumes when starting the container.
Dockerfile script:
#Create directories inside the container for tools and Dotfuscator
RUN mkdir -p /usr/local/tools /usr/local/dotfuscator
#Set environment variables for Dotfuscator to find the tools
ENV ILASM_PATH=/usr/local/tools/ilasm
ENV ILDASM_PATH=/usr/local/tools/ildasm
ENV DOTFUSCATOR_PATH=/usr/local/dotfuscator
#Copy Dotfuscator and its configuration file into the container
COPY /path/to/dotfuscator /usr/local/dotfuscator
COPY /path/to/dotfuscatorconfig.xml /usr/local/dotfuscator/dotfuscatorconfig.xml
#Define the default command to run Dotfuscator with the provided configuration
# For Example: CMD ["dotfuscator", "/usr/local/dotfuscator/dotfuscatorconfig.xml"]Run the container by mounting the required tools from the host machine.
Example:
docker run -it --name dotnet-dotfuscator-container \
-v /path/on/host/ilasm:/usr/local/tools/ilasm \
-v /path/on/host/ildasm:/usr/local/tools/ildasm \
-v /path/on/host/ilasm:/usr/local/tools/ilasm: Mounts the ilasm tool from your host machine to the container.
-v /path/on/host/ildasm:/usr/local/tools/ildasm: Mounts the ildasm tool from your host machine to the container.Use this approach when the tools are managed outside the Docker image or shared across multiple containers.
Related Articles
- Use Dotfuscator on Build Agents
- Integrate with Azure Pipelines
- Protect Your App with MSBuild
- Command-Line Interface
-
Activation