Running Docker containers
From Tech-Wiki
More actions
Windows container examples covering image pulls, interactive containers, image commits, Dockerfiles, IIS containers and remote IIS management.
Pull and run a Nano Server image
Pull Nano Server
docker pull mcr.microsoft.com/windows/nanoserver:ltsc2022
List local images:
List images
docker images
Start an interactive container:
Run Nano Server
docker run -it mcr.microsoft.com/windows/nanoserver:ltsc2022 cmd.exe
Inside the container:
echo "Hello World!" > Hello.txt exit
Commit a modified container
Review stopped containers
docker ps -a
Create an image from a container
docker commit <containerid> helloworld
Run the resulting image:
Read the sample file
docker run --rm helloworld cmd.exe /s /c type Hello.txt
IIS container
Pull the Windows IIS image
docker pull mcr.microsoft.com/windows/servercore/iis
Example Dockerfile:
FROM mcr.microsoft.com/windows/servercore/iis
RUN mkdir C:\Temp
COPY *.ps1 /Temp
RUN powershell -Command blah blah…
RUN powershell -File /Temp/blah.ps1
WORKDIR /inetpub/wwwroot
COPY app1/ .Build and run:
Build the image
docker build -t test-image .
Run the IIS container
docker run -d -p 8080:80 --name test-container test-image
Inspect the container IP information:
docker inspect -f "{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}" test-container
IIS Manager remote administration example
The original article enables the IIS Management Service and creates a local administrator inside the image:
FROM mcr.microsoft.com/windows/servercore/iis:windowsservercore-ltsc2022
RUN net user admin p4ssw0rd /ADD
RUN net localgroup administrators admin /ADD
RUN powershell.exe -command \
Install-WindowsFeature Web-Mgmt-Service; \
Set-ItemProperty -Path "HKLM:SOFTWARE\Microsoft\WebManagement\Server" -Name "EnableRemoteManagement" -Value 1; \
Set-Service WMSVC -StartupType Automatic;Do not reuse example passwords
Replace the demonstration local-account password with an approved secret-management approach before using a similar build in another environment.