Difference between revisions of "Running Docker containers"
From Tech-Wiki
(Created page with "Category:Microsoft '''Back to Windows Server''' Install Container feature, install [Docker https://www.docker.com/products/docker-desktop/]....") |
|||
(24 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
− | Install Container feature, install [ | + | Install Container feature, install [https://www.docker.com/products/docker-desktop/ Docker]. |
+ | |||
Pull an image | Pull an image | ||
Line 27: | Line 28: | ||
docker pull mcr.microsoft.com/windows/servercore/iis | docker pull mcr.microsoft.com/windows/servercore/iis | ||
− | + | Dockerfile example | |
FROM mcr.microsoft.com/windows/servercore/iis | FROM mcr.microsoft.com/windows/servercore/iis | ||
+ | RUN mkdir C:\Temp | ||
+ | COPY *.ps1 /Temp | ||
RUN powershell -Command blah blah… | RUN powershell -Command blah blah… | ||
− | RUN powershell -File blah.ps1 | + | RUN powershell -File /Temp/blah.ps1 |
− | ADD | + | WORKDIR /inetpub/wwwroot |
+ | COPY app1/ . # or ADD app1 /inetpub/wwwroot | ||
Run it | Run it | ||
− | docker build -t | + | docker build -t test-image . |
− | docker run -d -p | + | docker run -d -p 8080:80 --name test-container test-image |
+ | docker inspect -f <nowiki>"{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}"</nowiki> test-container | ||
+ | |||
+ | For IIS, install [https://www.iis.net/downloads/microsoft/iis-manager IIS Manager for Remote Administration], create local account on container, and enable service using this Dockerfile | ||
+ | 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; |
Latest revision as of 22:13, 27 December 2023
Install Container feature, install Docker.
Pull an image
docker pull mcr.microsoft.com/windows/nanoserver:ltsc2022
List images
docker images
Run image
docker run -it mcr.microsoft.com/windows/nanoserver:ltsc2022 cmd.exe echo "Hello World!" > Hello.txt exit
Update image
docker ps -a docker commit <containerid> helloworld docker ps -a (now it shows 2)
Run this custom image
docker run --rm helloworld cmd.exe /s /c type Hello.txt
Pull IIS
docker pull mcr.microsoft.com/windows/servercore/iis
Dockerfile example
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/ . # or ADD app1 /inetpub/wwwroot
Run it
docker build -t test-image . docker run -d -p 8080:80 --name test-container test-image docker inspect -f "{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}" test-container
For IIS, install IIS Manager for Remote Administration, create local account on container, and enable service using this Dockerfile
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;