Introduction
This guide explains how to use Docker and set up a Windows container for a .NET application without Docker Desktop. Follow these steps to install Docker, configure your environment, and deploy your .NET app in a container.
Prerequisites
Before starting, ensure:
Hyper-V is enabled on your Windows machine.
Step 1: Install Docker on Windows
1. Open PowerShell as Administrator
Run PowerShell with admin rights to execute Docker installation commands.
2. Configure Your System for Containers & Install Docker
Run the following PowerShell script to enable Windows features for containers and install.
Please refer : Microsoft Document
Docker:
Invoke-WebRequest -UseBasicParsing "https://raw.githubusercontent.com/microsoft/Windows-Containers/Main/helpful_tools/Install-DockerCE/install-docker-ce.ps1" -o install-docker-ce.ps1
.\install-docker-ce.ps1This will set up Docker on your Windows machine.
Step 2: Set Up Docker Environment Variables
3. Create a Docker Folder & Update System Path
Open File Explorer and go to
C:\Program Files\.Create a new folder named Docker.
Add this folder to the system environment variables:
Search for "Environment Variables" in Windows and open it.
Under System Variables, find Path, click Edit, and add:
C:\Program Files\Docker
4. Run Additional Setup Scripts
Execute the below PowerShell scripts one after another:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 Start-BitsTransfer -Source "https://github.com/docker/compose/releases/download/v2.35.0/docker-compose-windows-x86_64.exe" -Destination $Env:ProgramFiles\Docker\docker-compose.exe5. Verify Docker Installation
Open PowerShell or Command Prompt and run:
docker-compose -v
If installed correctly, this will display the Docker Compose version.
Step 3: Install Azure CLI (Optional but Recommended)
Download and install the 64-bit version of Azure CLI
Step 4: Configure Docker Settings
6. Update Docker Configuration (daemon.json)
Navigate to:
C:\ProgramData\docker\config
Open (or create) daemon.json in a text editor.
Make Sure update TCP and file look like as below
7. Add Docker Environment Variable
Open Environment Variables again.
Under System Variables, click New and add:
Variable Name:
DOCKER_HOSTVariable Value:
tcp://127.0.0.1:2376
8. Test Docker Commands
Run the following in both admin and non-admin Command Prompt:
docker imagesIf Docker is working, this will list available images (empty if none exist).
Step 5: Create a Docker Image for .NET Application
Folder Structure
Organize your project as follows:
ProjectFolder/ │── Dockerfile │── SpendSmart.csproj │── (Other project files)
Dockerfile Example
FROM mcr.microsoft.com/dotnet/aspnet:8.0-windowsservercore-ltsc2019 AS base WORKDIR /app EXPOSE 5000 ENV ASPNETCORE_URLS=http://+:5000 FROM mcr.microsoft.com/dotnet/sdk:8.0-windowsservercore-ltsc2019 AS build ARG configuration=Release WORKDIR /src COPY ["SpendSmart.csproj", "./"] RUN dotnet restore "SpendSmart.csproj" COPY . . WORKDIR "/src/." RUN dotnet build "SpendSmart.csproj" -c $configuration -o /app/build RUN dotnet publish "SpendSmart.csproj" -c $configuration -o /app/publish /p:UseAppHost=false FROM base AS final WORKDIR /app COPY --from=build /app/publish . ENTRYPOINT ["dotnet", "SpendSmart.dll"]
Build the Docker Image
Run this command in the folder containing the Dockerfile:
docker build -t spendsmart:latest .
Run the Docker Container
docker run -d -p 5000:5000 --name spendsmart_container spendsmart:latest
Verify the Application
Open a browser and navigate to:
http://localhost:5000
Conclusion
You’ve successfully set up Docker on Windows without Docker Desktop and deployed a .NET application in a container. This method is useful for developers who prefer lightweight Docker setups.
====================================
FAQ
Q1. Can I run Docker on Windows without Docker Desktop?
Yes — Docker can be installed directly on Windows using PowerShell scripts without needing Docker Desktop at all. This approach uses Docker Community Edition (CE) installed via the official Microsoft Windows Containers script, which sets up the Docker daemon natively. This is useful for developers who want a lightweight setup or work in environments where Docker Desktop licensing is a concern.
Q2. What is the difference between Windows containers and Linux containers in Docker?
Linux containers run a Linux kernel and are the default Docker container type — they work on most cloud platforms and CI/CD systems. Windows containers run a Windows kernel and are required when your application depends on Windows-specific APIs, COM components, or .NET Framework libraries that cannot run on Linux. The Dockerfile in this guide uses windowsservercore-ltsc2019 base images specifically because the .NET application targets Windows runtime.
Q3. Why do I need Hyper-V enabled to run Docker on Windows?
Docker on Windows uses Hyper-V to create an isolated virtualisation layer that runs containers. Without Hyper-V enabled, the Docker daemon cannot create the necessary virtual machine environment to isolate and run containers securely. You can enable Hyper-V through Windows Features or by running Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All in an admin PowerShell session.
Q4. What does the DOCKER_HOST environment variable do?
DOCKER_HOST tells Docker client tools which daemon to connect to. Setting it to tcp://127.0.0.1:2376 instructs the Docker CLI to communicate with the local Docker daemon over TCP on port 2376 instead of the default named pipe. This is necessary when running Docker without Desktop because the daemon is configured to listen on TCP rather than the default Windows named pipe socket.
Q5. What is the difference between docker build and docker run?
docker build reads your Dockerfile and creates a reusable image — think of it as compiling your application into a portable snapshot. docker run takes that image and starts a live container from it. You only need to run docker build again when your code or Dockerfile changes. You can run docker run multiple times from the same image to spin up multiple container instances simultaneously.
Q6. Why does the Dockerfile use a multi-stage build?
The Dockerfile in this guide uses two stages — a build stage using the full .NET SDK image and a final stage using only the smaller ASP.NET runtime image. This matters because the SDK image is several gigabytes larger than the runtime image. By copying only the published output into the final stage, your resulting Docker image stays lean, faster to pull, and contains no build tools or source code — only what the application needs to run.
Q7. How do I check if my .NET application is running inside the Docker container?
After running docker run -d -p 5000:5000 --name spendsmart_container spendsmart:latest, open a browser and go to http://localhost:5000. If the page loads, the container is running correctly. You can also run docker ps to see all running containers and their port mappings, or docker logs spendsmart_container to view the application's console output and spot any startup errors.
Q8. What should I do if docker images returns an error in non-admin Command Prompt?
This usually means the Docker daemon is not accessible to non-admin users. Ensure the DOCKER_HOST environment variable is set correctly to tcp://127.0.0.1:2376 under System Variables — not just User Variables. After updating environment variables, close and reopen your Command Prompt completely for the change to take effect. If the error persists, verify the Docker service is running by checking services.msc for the Docker service status.
==================================
you may like below blogs:
Azure DevOps YAML Pipeline: Stages, Jobs, Steps and Triggers Explained

