Installing docker container on windows 10 for Linux virtual machine

Lets install docker on windows 10 x64 machine to launch Linux ubuntu image as a container service.




During installation i have came across multiple issues specially in second phase which you may or may not encounter.

Follow the steps and read through support article link in case steps doesn't match in your setup   

Step 1 : Pre-requisites for Docker Installation 

Make sure Hyper-V is enabled on the local machine where docker software to be installed 

Start -> Settings -> App & Features -> Programs & features (related settings) <same available under Control Panel\Programs\Programs and Features> -> Turn windows feature on or off 



tick on both Hyper-V options and click "ok" and reboot the local machine 

Verify in cmd <open from start> -> systeminfo  <enter command> 



Hypervisor should get detected , if not same need to be enabled from BIOS setting under virtualization option 

systeminfo | find "System Type"


Step 2 : Docker Software Installation 

Download the docker for desktop installer software from following link 

https://docs.docker.com/desktop/windows/install/


Which should look like this 
 





Right click the downloaded "Docker desktop Installer" setup file and run as administrator 



Follow the snaps below as they appear during installation "click ok" to begin 













Installation successfully completed , click on "Close and restart" , reboot the local machine 






Step 3 : Subscribe to Docker  

docker id is required in order to login to docker

Open the recently installed docker application , refer the top part to sign in to docker website




After supplying your email information select the plan as per you need , i have selected personal here no credit card information required.
 



At this stage you will have docker id and credentials to login .




Step 4 : Preparation to run Docker Container  

i)

Create two directories "D:\Linux" & "D:\Linux_Con" as below which will be used to keep container binary and image





ii)






iii)

Download the xz application to extract the above downloaded image 

https://sourceforge.net/projects/xz-for-windows/

Run the xz application with downloaded setup file from location as below  




Copy the Ubuntu container image .vhdx file that was unzipped at the previous step to uvm.vhdx under D:\Linux_Con




iv)

Need to enable the "Windows Subsystem for Linux" optional feature before installing any Linux distributions on Windows.

Open PowerShell as Administrator and run:

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart









Step 5 : Configuration to run Docker Container  

i)

Create a setperm.ps1 file with below content 

param(
[string] $Root
)
# Give the virtual machines group full control
$acl = Get-Acl -Path $Root
$vmGroupRule = new-object System.Security.AccessControl.FileSystemAccessRule("NT VIRTUAL MACHINE\Virtual Machines", "FullControl","ContainerInherit,ObjectInherit", "None", "Allow")
$acl.SetAccessRule($vmGroupRule)
Set-Acl -AclObject $acl -Path $Root



ii)

Run below from admin power shell to run unsigned Powershell scripts.

Set-ExecutionPolicy -Scope process unrestricted







.\setperm.ps1 "D:\Linux_Con"





Step 6 : Running the container & troubleshooting 


i)

download the docker.exe and dockerd.exe required for running container service and pulling images

https://master.dockerproject.org/











Open the command prompt as an administrator 




Run below on command prompt 


set LCOW_SUPPORTED=1


.\dockerd.exe -D --data-root “D:\Linux”




Keep it running 


ii)

Pull ubuntu image from docker repository  


.\docker.exe pull ubuntu




iii)

Run the docker container   


.\docker.exe run -it ubuntu








Success ! You have achieved it ! Linux image docker container is up & running now !

if not refer troubleshooting steps as below 

Troubleshooting :

If you find Docker engine is stopped , which means some of the pre-requisites are not met or permission issue





Try restarting docker services as below from admin command prompt





If still problem persists try restarting local machine and at the start of the docker GUI you will be notified about the problem which will be mostly related to WSL , follow the link exactly to fix the same 

Manual installation steps for older versions of WSL | Microsoft Docs

On Completion of the Linux distribution  follow the steps 






Open PowerShell and run this command to set WSL 2 as the default version when installing a new Linux distribution:

wsl --set-default-version 2





D:\downloads>.\dockerd.exe -D --data-root "D:\Linux"
time="2021-10-20T14:16:46.272809700+05:30" level=info msg="Starting up"
failed to load listeners: open //./pipe/docker_engine: Access is denied.



Above error is ignorable repeat the Step 6 ii) onwards 
    


Also Refer below link for more information    

Run Linux containers on Windows | Ubuntu














No comments:

Post a Comment