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.ps1
This 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.exe
5. 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_HOST
Variable Value:
tcp://127.0.0.1:2376
8. Test Docker Commands
Run the following in both admin and non-admin Command Prompt:
docker images
If 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.
Need help? Contact us.