Learn the simple commands to use on Powershell for installing Docker on Windows 10 with WSL 2 support for creating an optimized and fast container environment to run various Virtual machine images.
Remove deprecated MAINTAINER instruction and add metadata with LABEL (chocolatey#2361). Add 'choco.exe' to path, so both 'choco' and 'choco.exe' can be used, like Windows supports (chocolatey#2362). Change the install location to '/opt/chocolatey' as that is more in line with the Linux filesystem hierarchy (chocolatey#2360). This article assumes you have a place to run windows containers, docker, and a minimal amount of docker experience. You can run this on a windows 10 machine, Server 2016 with Hyper-V, or Azure. The complete code is posted below, but lets break it up a bit and walk through small pieces and point out some of the variations on the source of the.
Well, when it comes to installing Docker on Windows 10, most of us struggle with the problem of enabling Hyper-V because it won’t work properly without that. However, if we don’t want to use Hyper-V for Docker installation then using WSL 2 support would be a good idea.
WSL which is already available in the Windows 10 operating system and now comes with the ability to run full-fledged Linux kernel using WSL 2, makes it very easy to operate Docker without Hyper-V or VirtualBox.
Steps to run the container. Docker run -name mycontainer mhhaji/winserver2016base:v1 ping -t localhost. Docker exec -it mycontainer powershell. Once powershell is running, I execute the following commands. Get-PackageProvider #Chocolatey is not existing so I install chocolatey Find-Package -Provider chocolatey #Enter Y when prompted #. Cannot uninstall Docker Desktop via Chocolatey. 5th March 2021 chocolatey, docker. I’ve installed Docker 2.4 quite some time ago using Chocolatey (my OS is Win 10). Since updating Docker using choco upgrade all always failed, I did the updates manually via the Docker itself (right-click → Check for Updates → etc.).

Read More:Tutorial to install Docker on Windows 7 without Hyper-V.
Pre-requisites:

Chocolatey In Docker
- Windows 10 OS
- Admin access
- Powershell
- WSL- Windows Subsystem for Linux
- Internet connection
Install Docker using Powershell on Windows 10 with a single command
Most of us download and use the executable file available on the official website of this containerized platform to set it up, however, you don’t have to do all that. Just use the command line, follow the below steps, and you are done.
Note: Make sure the WSL- Windows subsystem for Linux is already enabled on your system before performing the below-given steps.
Open PowerShell as Admin
We need to have the Administrator access of PowerShell to run the installation command for Docker, thus, right-click on the Windows 10 Start button and select the “Windows PowerShell (Admin)” option.
Install Chocolatey
Just like Linux packages managers, for example, DNF of CentOS and APT available in Ubuntu, one is also available for Windows operating systems called Chocolatey. The command tool used by this Windows package manager is choco
.
Run the below command to enable it in Powershell
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString(‘https://chocolatey.org/install.ps1’))
Note: Once the Chocolatey is on your system, close the Powershell and reopen it as Admin.
Command to install Docker Desktop using PowerShell on Windows
Now, everything is ready on Powershell and we can use the Choco command to install Docker on Windows 10 Desktop or Windows Server OS.
When the above command asks for your permission to install the packages, allow it by typing A and hitting the Enter key.
Run Docker Desktop
You will see the icon on your desktop to run this open source containerized platform, double click on that. And start it.
Configure WSL 2 Distro
Although after installing the Docker, it will automatically install its own WSL 2 Linux distro on your system as the default one. Thus, you can easily start using it from PowerShell. In case you want to enable the docker support to other available WSL Linux distros then simply go to the Docker Desktop app, select the Resources option given on the left side, and select WSL integration. You will find all installed and available WSL distros there, use the toggle button given in the front of the distro to enable the support. After that, the particular WSL Linux distro for which you have enabled its support can directly run all the Docker commands without actually installing on that distro.
Extra Tip: Convert WSL 1 distro to WSl 2
Chocolatey Docker Compose
In case your WSL distro is still on WSl 1 then you have to first enable the WSL 2 support. For that run your Powershell as Admin and use this command:
Chocolatey Docker Cli
Now, go to the Microsoft page to download the WSL 2 kernel update setup, use this link to directly download and upgrade the kernel.
Once all this done, simply restart the system.
Now, open Powershell again as admin and type:
The above command will show all the installed WSL distro on your system. Find out the name of one which you want to convert. For example, we have Ubuntu-18.04 WSL distro and to convert it from WSL 1 to WSL 2, we will run the command:
wsl --set-version distro-name 2
So, as per the example, the command will be like this:
I hope this article somehow helped you, if you have any query please feel free to comment.