GHOSTby AlphaBravo
CatalogWhy GhostContactAccount
Ghost Container Registry — Secure, signed, FIPS-ready images·Built by AlphaBravo
Catalog/dotnet/Guides

.net

Languages & frameworks

.NET is the free, open-source, cross-platform framework for building modern apps and powerful cloud services.

OverviewGuidesTags

Quick Start

Pull the latest version of this image from the Ghost registry. Pulling requires authentication — generate a token and run docker login first (see Authentication below).

Authentication

The Ghost catalog is public to browse, but pulling images requires an account. Generate a pull token below (or from your Account → Tokens page) — you'll get a ready-to-paste docker login command, then docker pull works.

The username is generated automatically (it looks like robot$<project>+<auto-id>, not the name you typed) and is included in the docker login command above. The secret is shown only once when you create the token.

Verify Signature

All Ghost images are signed with cosign. Verifying the signature before deployment ensures the image has not been tampered with.

Install cosign via brew install cosign or download from the Sigstore releases page.

Using This Image

Reference this image in your Dockerfile as a base layer:

Additional Notes

Prerequisites

All examples in this guide use the public image. If you’ve mirrored the repository for your own use (for example, to your Docker Hub namespace), update your commands to reference the mirrored image instead of the public one.

For example:

  • Public image: registry.ghost-prod.alphabravo.io/ghost-base/<repository>:<tag>
  • Mirrored image: <your-namespace>/dhi-<repository>:<tag>

For the examples, you must first use docker login registry.ghost-prod.alphabravo.io to authenticate to the registry to pull the images.

What's included in this .NET image

This Docker Hardened .NET image provides secure, production-ready variants for both development and runtime scenarios:

Runtime variants include:

  • .NET runtime for running compiled applications
  • Essential libraries and dependencies
  • Optimized for minimal attack surface

SDK variants (tagged with -sdk) include:

  • Complete .NET SDK for building applications
  • Package managers and development tools

On this page

Quick StartAuthenticationVerify SignatureUsing This ImageAdditional Notes
  • Build tools and compilers
  • Shell access for development workflows
  • Start a .NET application

    Run the following command:

    # Run a .NET application (runtime variant)
    docker run --rm registry.ghost-prod.alphabravo.io/ghost-base/dotnet:<tag>
    
    # Start an interactive development container (SDK variant)
    docker run --rm -it --entrypoint bash registry.ghost-prod.alphabravo.io/ghost-base/dotnet:<tag>-sdk
    

    To inspect the image configuration:

    # Check entry point and user configuration
    docker image inspect registry.ghost-prod.alphabravo.io/ghost-base/dotnet:8 --format='{{.Config.Entrypoint}}'
    docker image inspect registry.ghost-prod.alphabravo.io/ghost-base/dotnet:8 --format='{{.Config.Cmd}}'
    docker image inspect registry.ghost-prod.alphabravo.io/ghost-base/dotnet:8 --format='{{.Config.User}}'
    
    # Compare image sizes
    docker images | grep dotnet
    

    Common .NET use cases

    Build and run a .NET console application

    Use a multi-stage Dockerfile to build your application with the SDK variant and run with the runtime variant:

    # Build stage using SDK variant
    FROM registry.ghost-prod.alphabravo.io/ghost-base/dotnet:8-sdk AS build
    WORKDIR /src
    COPY *.csproj .
    RUN dotnet restore
    COPY . .
    RUN dotnet publish -c Release -o /app
    
    # Runtime stage using minimal runtime variant
    FROM registry.ghost-prod.alphabravo.io/ghost-base/dotnet:8
    WORKDIR /app
    COPY --from=build /app .
    ENTRYPOINT ["dotnet", "YourApp.dll"]
    

    Build and run commands:

    docker build -t my-console-app .
    docker run --rm my-console-app
    

    ASP.NET Core web application

    For web applications, use the ASP.NET Core runtime from the separate DHI ASP.NET Core repository:

    # Build stage
    FROM registry.ghost-prod.alphabravo.io/ghost-base/dotnet:8-sdk AS build
    WORKDIR /src
    COPY MyWebApp/*.csproj ./MyWebApp/
    RUN dotnet restore MyWebApp/MyWebApp.csproj
    COPY . .
    RUN dotnet publish MyWebApp/MyWebApp.csproj -c Release -o /app
    
    # Runtime stage for web apps
    FROM registry.ghost-prod.alphabravo.io/ghost-base/aspnetcore:8
    WORKDIR /app
    COPY --from=build /app .
    EXPOSE 8080
    ENTRYPOINT ["dotnet", "MyWebApp.dll"]
    

    Configure your ASP.NET Core application for nonroot user compatibility:

    // In Program.cs, ensure proper port configuration
    var builder = WebApplication.CreateBuilder(args);
    var app = builder.Build();
    
    app.MapGet("/", () => "Hello World from DHI .NET Web App!");
    app.MapGet("/health", () => new { status = "healthy", timestamp = DateTime.UtcNow });
    
    // Use port 8080 (nonroot user compatible)
    app.Run("http://0.0.0.0:8080");
    

    Build and run commands:

    docker build -t my-web-app .
    docker run -d --name my-web-app -p 8080:8080 my-web-app
    
    # Test endpoints
    curl http://localhost:8080/
    curl http://localhost:8080/health
    
    # Clean up
    docker stop my-web-app && docker rm my-web-app
    

    Development container with volume mounting

    Mount your source code for live development:

    # Start an interactive development environment
    docker run --rm -it \
      -v $(pwd):/workspace \
      -w /workspace \
      registry.ghost-prod.alphabravo.io/ghost-base/dotnet:8-sdk \
      bash
    

    Inside the container, you can run complete development workflows:

    # Create a new project
    dotnet new console -n MyApp
    cd MyApp
    
    # Add packages
    dotnet add package Newtonsoft.Json
    
    # Build and run
    dotnet build
    dotnet run
    
    # Run tests
    dotnet test
    
    # Publish for production
    dotnet publish -c Release -o ./publish
    

    For quick development tasks without entering the container:

    # Create a new project from outside the container
    docker run --rm -v $(pwd):/workspace -w /workspace \
      registry.ghost-prod.alphabravo.io/ghost-base/dotnet:8-sdk \
      dotnet new web -n MyWebApp
    
    # Build the project
    docker run --rm -v $(pwd):/workspace -w /workspace \
      registry.ghost-prod.alphabravo.io/ghost-base/dotnet:8-sdk \
      dotnet build MyWebApp
    
    # Create and run a simple console application
    docker run --rm -v $(pwd):/workspace -w /workspace \
      registry.ghost-prod.alphabravo.io/ghost-base/dotnet:8-sdk \
      dotnet new console -n HelloWorld
    
    docker run --rm -v $(pwd):/workspace -w /workspace \
      registry.ghost-prod.alphabravo.io/ghost-base/dotnet:8-sdk \
      dotnet run --project HelloWorld
    

    Running pre-built applications

    Execute .NET CLI commands to run pre-built applications:

    # Create and build a console application using SDK
    docker run --rm -v $(pwd):/workspace -w /workspace \
      registry.ghost-prod.alphabravo.io/ghost-base/dotnet:8-sdk \
      dotnet new console -n MyApp
    
    docker run --rm -v $(pwd):/workspace -w /workspace \
      registry.ghost-prod.alphabravo.io/ghost-base/dotnet:8-sdk \
      dotnet build MyApp
    
    # Run the built application using runtime image (note the full path to the compiled DLL)
    docker run --rm -v $(pwd):/workspace -w /workspace \
      registry.ghost-prod.alphabravo.io/ghost-base/dotnet:8 \
      dotnet MyApp/bin/Debug/net8.0/MyApp.dll
    

    Note: When using dotnet build, the compiled DLL is placed in bin/Debug/net8.0/ (or bin/Release/net8.0/ for release builds). When using dotnet publish in multi-stage builds, the DLL is copied directly to the specified output directory (/app in the examples above), which is why the multi-stage examples work with just the DLL name.

    Kubernetes deployment

    Deploy your .NET application to Kubernetes:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: dotnet-app
    spec:
      replicas: 3
      selector:
        matchLabels:
          app: dotnet-app
      template:
        metadata:
          labels:
            app: dotnet-app
        spec:
          containers:
            - name: dotnet-app
              image: <your-namespace>/my-dotnet-app:latest
              ports:
                - containerPort: 8080
              env:
                - name: ASPNETCORE_ENVIRONMENT
                  value: "Production"
                - name: ASPNETCORE_URLS
                  value: "http://0.0.0.0:8080"
              livenessProbe:
                httpGet:
                  path: /health
                  port: 8080
                initialDelaySeconds: 30
                periodSeconds: 10
              readinessProbe:
                httpGet:
                  path: /health
                  port: 8080
                initialDelaySeconds: 5
                periodSeconds: 5
              resources:
                requests:
                  memory: "128Mi"
                  cpu: "100m"
                limits:
                  memory: "256Mi"
                  cpu: "500m"
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: dotnet-app-service
    spec:
      selector:
        app: dotnet-app
      ports:
        - port: 80
          targetPort: 8080
      type: LoadBalancer
    

    Use Docker Compose

    This is an example pattern for local development. This example cannot be run as-is and requires a complete application setup:

    version: "3.8"
    services:
      app:
        build: .
        ports:
          - "8080:8080"
        environment:
          - ASPNETCORE_ENVIRONMENT=Development
          - ASPNETCORE_URLS=http://0.0.0.0:8080
        volumes:
          - ./logs:/app/logs
        depends_on:
          - db
    
      db:
        image: postgres:15
        environment:
          POSTGRES_DB: myapp
          POSTGRES_USER: user
          POSTGRES_PASSWORD: password
        ports:
          - "5432:5432"
        volumes:
          - postgres_data:/var/lib/postgresql/data
    
    volumes:
      postgres_data:
    

    Note: This is provided as a reference pattern only. To use this, you would need:

    • A working Dockerfile in your project root
    • An ASP.NET Core application configured to connect to PostgreSQL
    • Proper Entity Framework or database connection setup

    Docker Official Images vs. Ghost hardened images

    FeatureDocker Official .NETDocker Hardened .NET
    SecurityStandard base with common utilitiesMinimal, hardened base with security patches
    Shell accessFull shell (bash/sh) availableNo shell in runtime variants, available in SDK variants
    Package managerapt/apk availableNo package manager in runtime variants
    UserRuns as root by defaultRuntime variants run as nonroot user
    Attack surfaceLarger due to additional utilitiesMinimal, only essential components
    Image sizeLarger (500MB-1.2GB)Smaller (200MB-800MB)
    CVEsMay contain known vulnerabilitiesZero known CVEs at publish time
    DebuggingTraditional shell debuggingUse Docker Debug or Image Mount for troubleshooting
    Base OSVarious Debian/Alpine versionsHardened Alpine 3.22 or Debian 13 base
    ComplianceStandard complianceFIPS-compliant and STIG-certified variants available

    Why no shell or package manager?

    Ghost hardened images prioritize security through minimalism:

    • Reduced attack surface: Fewer binaries mean fewer potential vulnerabilities
    • Immutable infrastructure: Runtime containers shouldn't be modified after deployment
    • Compliance ready: Meets strict security requirements for regulated environments

    The hardened images intended for runtime don't contain a shell nor any tools for debugging. Common debugging methods for applications built with Ghost hardened images include:

    • Docker Debug to attach to containers
    • Docker's Image Mount feature to mount debugging tools
    • Ecosystem-specific debugging approaches

    Docker Debug provides a shell, common debugging tools, and lets you install other tools in an ephemeral, writable layer that only exists during the debugging session.

    For example, you can use Docker Debug:

    # Start your application
    docker run -d --name my-app registry.ghost-prod.alphabravo.io/ghost-base/dotnet:8
    
    # Attach debugger
    docker debug my-app
    

    or mount debugging tools with the Image Mount feature:

    docker run --rm -it --pid container:my-dotnet-app \
      --mount=type=image,source=registry.ghost-prod.alphabravo.io/ghost-base/busybox,destination=/dbg,ro \
      registry.ghost-prod.alphabravo.io/ghost-base/dotnet:8 /dbg/bin/sh
    

    Image variants

    Ghost hardened images come in different variants depending on their intended use.

    Runtime variants are designed to run your application in production. These images are intended to be used either directly or as the FROM image in the final stage of a multi-stage build. These images typically:

    • Run as the nonroot user
    • Do not include a shell or a package manager
    • Contain only the minimal set of libraries needed to run the app

    Build-time variants (SDK variants) typically include -sdk in the variant name and are intended for use in the first stage of a multi-stage Dockerfile. These images typically:

    • Run as the root user
    • Include a shell and package manager
    • Are used to build or compile applications
    • Include the complete .NET SDK toolchain

    Available variants include:

    • 8: .NET 8 runtime only
    • 8-sdk: .NET 8 SDK for development and building
    • 9: .NET 9 runtime only
    • 9-sdk: .NET 9 SDK for development and building

    For ASP.NET Core application, use the separate DHI ASP.NET Core repository:

    • registry.ghost-prod.alphabravo.io/ghost-base/aspnetcore:8: ASP.NET Core 8 runtime
    • registry.ghost-prod.alphabravo.io/ghost-base/aspnetcore:9: ASP.NET Core 9 runtime

    Migrate to a Ghost hardened image

    To migrate your application to a Ghost hardened image, you must update your Dockerfile. At minimum, you must update the base image in your existing Dockerfile to a Ghost hardened image. This and a few other common changes are listed in the following table of migration notes.

    ItemMigration note
    Base imageReplace your base images in your Dockerfile with a Ghost hardened image.
    Package managementNon-SDK images, intended for runtime, don't contain package managers. Use package managers only in images with a -sdk tag.
    Non-root userBy default, non-SDK images, intended for runtime, run as the nonroot user. Ensure that necessary files and directories are accessible to the nonroot user.
    Multi-stage buildUtilize images with a -sdk tag for build stages and runtime images for runtime. For ASP.NET Core apps, use dhi-aspnetcore images for runtime.
    TLS certificatesGhost hardened images contain standard TLS certificates by default. There is no need to install TLS certificates.
    PortsNon-SDK hardened images run as a nonroot user by default. As a result, applications in these images can’t bind to privileged ports (below 1024) when running in Kubernetes or in Docker Engine versions older than 20.10. To avoid issues, configure your application to listen on port 1025 or higher inside the container.
    Entry pointGhost hardened images may have different entry points than images such as Docker Official Images. Inspect entry points for Ghost hardened images and update your Dockerfile if necessary.
    No shellBy default, non-SDK images, intended for runtime, don't contain a shell. Use -sdk images in build stages to run shell commands and then copy artifacts to the runtime stage.

    The following steps outline the general migration process.

    1. Find hardened images for your app.

      A hardened image may have several variants. Inspect the image tags and find the image variant that meets your needs.

    2. Update the base image in your Dockerfile.

      Update the base image in your application's Dockerfile to the hardened image you found in the previous step. For framework images, this is typically going to be an image tagged as -sdk because it has the tools needed to install packages and dependencies.

    3. For multi-stage Dockerfiles, update the runtime image in your Dockerfile.

      To ensure that your final image is as minimal as possible, you should use a multi-stage build. All stages in your Dockerfile should use a hardened image.

      While intermediary stages will typically use images tagged as -sdk, your final runtime stage should use a runtime image variant.

    4. Install additional packages.

      Ghost hardened images contain minimal packages in order to reduce the potential attack surface. You may need to install additional packages in your Dockerfile. Inspect the image variants to identify which packages are already installed.

      Only images tagged as -sdk typically have package managers. You should use a multi-stage Dockerfile to install the packages. Install the packages in the build stage that uses a -sdk image. Then, if needed, copy any necessary artifacts to the runtime stage that uses a non-SDK image.

      For Alpine-based images, you can use apk to install packages. For Debian-based images, you can use apt-get to install packages.

    Before and after migration

    Before (using official images):

    FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
    WORKDIR /src
    COPY . .
    RUN dotnet publish -c Release -o /app
    
    FROM mcr.microsoft.com/dotnet/aspnet:8.0
    WORKDIR /app
    COPY --from=build /app .
    ENTRYPOINT ["dotnet", "MyApp.dll"]
    

    After (using DHI):

    FROM registry.ghost-prod.alphabravo.io/ghost-base/dotnet:8-sdk AS build
    WORKDIR /src
    COPY *.csproj .
    RUN dotnet restore
    COPY . .
    RUN dotnet publish -c Release -o /app
    
    FROM registry.ghost-prod.alphabravo.io/ghost-base/aspnetcore:8
    WORKDIR /app
    COPY --from=build /app .
    EXPOSE 8080
    ENTRYPOINT ["dotnet", "MyApp.dll"]
    

    Troubleshooting migration

    The following are common issues that you may encounter during migration.

    General debugging

    The hardened images intended for runtime don't contain a shell nor any tools for debugging. The recommended method for debugging applications built with Ghost hardened images is to use Docker Debug to attach to these containers. Docker Debug provides a shell, common debugging tools, and lets you install other tools in an ephemeral, writable layer that only exists during the debugging session.

    Permissions

    By default image variants intended for runtime, run as the nonroot user. Ensure that necessary files and directories are accessible to the nonroot user. You may need to copy files to different directories or change permissions so your application running as the nonroot user can access them.

    Privileged ports

    Non-SDK hardened images run as a nonroot user by default. As a result, applications in these images can't bind to privileged ports (below 1024) when running in Kubernetes or in Docker Engine versions older than 20.10. To avoid issues, configure your application to listen on port 1025 or higher inside the container, even if you map it to a lower port on the host. For example, docker run -p 80:8080 my-image will work because the port inside the container is 8080, and docker run -p 80:81 my-image won't work because the port inside the container is 81.

    No shell

    By default, image variants intended for runtime don't contain a shell. Use -sdk images in build stages to run shell commands and then copy any necessary artifacts into the runtime stage. In addition, use Docker Debug to debug containers with no shell.

    Entry point

    Ghost hardened images may have different entry points than images such as Docker Official Images. Use docker image inspect to inspect entry points for Ghost hardened images and update your Dockerfile if necessary.

    .NET-specific considerations

    • Global tools: Global .NET tools should be installed during the build stage using the SDK image
    • NuGet packages: All package restoration should happen in the SDK build stage
    • Runtime dependencies: Ensure all required runtime libraries are present in the final runtime image
    • Configurations: Use environment variables or configuration files that are accessible to the nonroot user
    • File paths: When running applications with dotnet build, the DLL is located in bin/Debug/net8.0/ or bin/Release/net8.0/ subdirectories. When using dotnet publish, the DLL is placed in the specified output directory.
    • Logging: Configure logging to write to stdout/stderr or to directories writable by the nonroot user
    • Health checks: Implement health check endpoints for Kubernetes liveness and readiness probes