Skip to main content

Posts

Showing posts with the label Docker

Creating and logging in to a Windows Containers user with a password

Windows Containers by default uses ContainerAdministator user account with blank password. Creating a new user with password can be done but cannot be used in DockerFile for example. If you want to use another user in a container you have to create a user with blank password! To login to a container with a password, do the following: PS C:\> $cert = New-SelfSignedCertificate -DnsName "dontcare" -CertStoreLocation Cert:\LocalMachine\My PS C:\> winrm create winrm/config/Listener?Address=*+Transport=HTTPS ('@{Hostname="notimportant"; CertificateThumbprint="' + $cert.Thumbprint + '"}') PS C:\> winrm set winrm/config/service/Auth '@{Basic="true"}' PS C:\> $cred = New-Object pscredential 'timus', (ConvertTo-SecureString -String 'P@$$w0rd' -AsPlainText -Force) PS C:\> Enter-PSSession -Credential $cred -ComputerName localhost -Authentication Basic -UseSSL -SessionOption (New-PSSessionOption -Skip

Windows containers cannot use USER instruction to change user with a password

 I have a Dockerfile like below: FROM mcr.microsoft.com/windows/servercore:20H2 as final RUN net user timus P@$$w0rd123!@# /add /Passwordchg:No RUN WMIC USERACCOUNT WHERE "Name='timus'" SET PasswordExpires=FALSE RUN net localgroup administrators timus /add USER timus RUN whoami Running this will fail with an error message like below: C:\mydocker>docker build -t myimages:1.0.0 -f Dockerfile Sending build context to Docker daemon 678.8MB Step 1/6 : FROM mcr.microsoft.com/windows/servercore:20H2 as final ---> 4943ff812624 Step 2/6 : RUN net user timus P@$$w0rd!@# /add /Passwordchg:No ---> Running in 95d4d70138d8 The command completed successfully. Removing intermediate container 95d4d70138d8 ---> d00130167ea2 Step 3/6 : RUN WMIC USERACCOUNT WHERE "Name='timus'" SET PasswordExpires=FALSE ---> Running in 0d05945d8f70 Updating property(s) of '\\0D05945D8F70\ROOT\CIMV2:Win32_UserAccount.Domain="0D05945D8F70",Name=&q

My docker cheat sheet

My docker cheat sheet Installing base container image for Server Core 2019. If you are running Windows Server 2019 virtual machine, this will allow you to run the container in process isolation mode instead of Hyper-V isolation. Process isolation is more light-weight and allows you to run a Server 2019 VM with dynamic memory setting in Hyper-V. PS C:\> docker image pull mcr.microsoft.com/windows/servercore:ltsc2019 To list downloaded images, do PS C:\> docker images This will show something like below PS C:\> docker images REPOSITORY TAG IMAGE ID CREATED SIZE mcr.microsoft.com/windows/servercore ltsc2019 3eaa9ebbf51f 5 weeks ago 5.25GB To run a Windows container based on servercore:ltsc2019, do: PS C:\> docker run -it mcr.microsoft.com/windows/servercore:ltsc2019 cmd.exe This will open a cmd.exe prompt. This should allow you to play inside that container. This contain

Can’t install Hyper-V Management Tools on Windows Server 2019 if the machine/VM does not support virtualization

Can’t install Hyper-V Management Tools on Windows Server 2019 if the machine/VM does not support virtualization   I tried to install PowerShell Direct to manage docker containers but can't install the feature, trying to run: PS C:\> Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Management-PowerShell  yields with error below: PS C:\Users\Administrator> Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Management-PowerShell Enable-WindowsOptionalFeature : One or several parent features are disabled so current feature can not be enabled. At line:1 char:1 + Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V- ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     + CategoryInfo          : NotSpecified: (:) [Enable-WindowsOptionalFeature], COMException     + FullyQualifiedErrorId : Microsoft.Dism.Commands.EnableWindowsOptionalFeatureCommand Apparently this happens when the OS is running on a ma