Compared with Windows, it's very simple because Docker is made for Linux and not Windows. You can find the official docker engine installation steps here.
Windows Subsystem for Linux (WSL) 2 is a full Linux kernel built by Microsoft, which allows Linux distributions to run without managing virtual machines. With Docker Desktop running on WSL 2, users can leverage Linux workspaces and avoid maintaining both Linux and Windows build scripts. In addition, WSL 2 provides improvements to file system sharing and boot time.
Note
You do not need Hyper-V when using WSL2. WSL2 is a separate virtualization technology that does not rely on Hyper-V. In fact, WSL2 uses a lightweight utility VM that leverages the Windows Hypervisor Platform (WHPX), which is a different component from Hyper-V.
When you're using Docker Desktop with WSL2, you can run Linux containers directly on top of WSL2 without the need for Hyper-V. This provides better performance and resource usage compared to using Docker with the Hyper-V backend.
However, note that if you want to use both WSL2 and Hyper-V on the same Windows system, you can do so without any issues, as they can coexist without any conflicts.
Caution
File system performance is critical for development. In WSL, the performance can be significantly lower when working on the Windows file system (mounted under /mnt/c/ or similar). To improve performance, move your code project to the Linux file system, which is typically faster.
This means you need to setup a ssh key in the folder ".ssh" and create a folder "git" in the home directory. (~/.ssh and ~/git)
- Open PowerShell or Windows Command Prompt in administrator mode by right-clicking and selecting "Run as administrator"
- Enter
wsl.exe --install.
This command will enable the features necessary to run WSL and install the Ubuntu distribution of Linux - Restart PC
Follow the instructions from here
When you install Ubuntu on Windows Subsystem for Linux (WSL), you can either choose the default Ubuntu distribution or a specific Long Term Support (LTS) release.
As Default "Ubuntu" is installed, this is the latest LTS distro of linux.
When running the wsl -l command, no version is explicitly specified in the name of the distro.
It is recommended to install a custom distro from the MS Store, these distro's have the version in the name.
- Go to the MS Store
- Search for "Ubuntu"
- Download Ubuntu 22.04 LTS and Open it
- Wait for installation and enter your username & pass
- Installation is complete now, verify in windows powershell (as admin) with the following command:
wsl -l -v - Set the Ubuntu 22.04 LTS as default distro with the following command:
wsl --set-default-version <distro-name> - Remove the other Ubuntu distro with the following command:
wsl --unregister <distro-name>
- Install docker engine from here
- Launch Docker Desktop, this should start docker engine
- Verify that docker engine is running with the following command in the terminal:
docker version
Caution
Docker Desktop terms, Commercial use of Docker Desktop in larger enterprises (more than 250 employees OR more than $10 million USD in annual revenue) requires a paid subscription.
-
Connect to WSL distro (ubuntu), via app or vis vs code wsl connection (via command palette)
-
Install docker ce (comminity edition) for ubuntu from the instructions here
-
Add current user to docker group
sudo groupadd docker sudo usermod -aG docker $USER -
Make sure docker engine starts on boot
- The following commands will open your /etc/sudoers file, which controls how sudo command are executed.
We’ll want to allow our user to start dockerd without being prompted for a password.
Add the following line to the bottom:
sudo visudo
- Add the following line to the file, make sure to change
<your-user-name>to your user name
<your-user-name> ALL=(ALL) NOPASSWD: /usr/bin/dockerd
- Now, we will update our shell profile file to automatically run the docker daemon if it’s not running yet.
This can be done by adding the following lines to your.bashrcor.zshrc
# Start Docker daemon automatically when logging in if not running. RUNNING=`ps aux | grep dockerd | grep -v grep` if [ -z "$RUNNING" ]; then sudo dockerd > /dev/null 2>&1 & disown fi
- Start docker engine manually with the following command:
sudo dockerd - Verify docker engine running with the following command:
docker images, this will list all installed images. When no are installed it will be empty. When something is not installed correctly, an error will be thrown.
- The following commands will open your /etc/sudoers file, which controls how sudo command are executed.
To ensure that the SSH agent is always available for managing your SSH keys, it is a good practice to auto-start the agent when you open a new terminal session. By adding the necessary commands to your .bashrc file, the SSH agent will be automatically started, making it more convenient for you to use SSH keys when connecting to remote servers.
The .bashrc file is a shell script that Bash runs whenever it is started interactively, which means that it is executed every time you open a new terminal window. By adding the SSH agent startup commands to this file, you ensure that the agent is consistently available across your terminal sessions.
- Open the
.bashrcor.zshrcfile with the following commandnano ~/.bashrcornano ~/.zshrc - Add the following to the end of your ~/.bashrc file:
# Auto add the .ssh private keys to the ssh agent if [ -z "$SSH_AUTH_SOCK" ]; then eval $(ssh-agent -s >/dev/null 2>&1) for key in ~/.ssh/id_*; do if [[ $key != *".pub" ]]; then # Avoid public keys ssh-add "$key" >/dev/null 2>&1 fi done fi
- Save the file and exit the text editor.
Now, the SSH agent will be auto-started in every new terminal session, making it easier for you to manage and use your SSH keys.