Docker Installation Log for WSL 2 on Windows

Eddie Gulay - Aug 19 - - Dev Community

I just started to learn about docker and i thought it will be a good idea to document the process. So here’s a concise yet descriptive log documenting the process of installing and configuring Docker entirely within WSL 2 on Windows. Each step includes a brief explanation of the purpose of the commands and the tools being installed.

1. Install and Configure WSL 2

  1. Install WSL (Windows Subsystem for Linux):
   wsl --install
Enter fullscreen mode Exit fullscreen mode
  • Purpose: Installs WSL, allowing you to run a full Linux kernel on your Windows machine.
  • Context: WSL enables a Linux environment directly within Windows, and WSL 2 uses a real Linux kernel for better compatibility and performance.
  1. Install a Linux Distribution (e.g., Ubuntu):

    • Action: Download and install Ubuntu from the Microsoft Store.
    • Purpose: Ubuntu provides a familiar Linux environment where Docker will be installed.
  2. Set WSL 2 as the Default Version:

   wsl --set-default-version 2
Enter fullscreen mode Exit fullscreen mode
  • Purpose: Ensures that new WSL instances use WSL 2, which offers improved performance and full system call compatibility.
  1. Launch the Linux Distribution:
    • Action: Open the installed Ubuntu distribution.
    • Purpose: This opens the Ubuntu terminal where all subsequent commands will be run.

2. Update and Install Prerequisites

  1. Update Package Information:
   sudo apt update && sudo apt upgrade
Enter fullscreen mode Exit fullscreen mode
  • Purpose: Updates the package lists and installs the latest versions of all installed packages.
  • Context: Ensures that your system is up-to-date before installing Docker.
  1. Install Required Packages:
   sudo apt install apt-transport-https ca-certificates curl software-properties-common
Enter fullscreen mode Exit fullscreen mode
  • apt-transport-https: Allows apt to use HTTPS for downloading packages, improving security.
  • ca-certificates: Ensures that your system trusts SSL certificates, necessary for secure communications.
  • curl: A command-line tool for transferring data with URLs, used to download the Docker GPG key.
  • software-properties-common: Provides tools for managing software repositories, enabling the addition of Docker’s repository.

3. Add Docker’s Official GPG Key and Repository

  1. Add Docker GPG Key:
   curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
Enter fullscreen mode Exit fullscreen mode
  • Purpose: Fetches and stores Docker’s GPG key, which is used to verify the authenticity of Docker packages.
  • Context: This step ensures that the Docker packages you install are legitimate and haven’t been tampered with.
  1. Set Up Docker’s APT Repository:
   echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Enter fullscreen mode Exit fullscreen mode
  • Purpose: Adds Docker’s official stable repository to your system’s package sources, allowing apt to download Docker directly from Docker’s servers.
  • Context: Docker’s official repository contains the latest, stable versions of Docker.

4. Install Docker

  1. Install Docker Engine and Related Tools:
   sudo apt update
   sudo apt install docker-ce docker-ce-cli containerd.io
Enter fullscreen mode Exit fullscreen mode
  • docker-ce: The Docker Community Edition, the core engine that runs Docker containers.
  • docker-ce-cli: Command-line tools for interacting with Docker, such as docker run and docker ps.
  • containerd.io: A container runtime that manages the lifecycle of containers, responsible for running and supervising containers.

5. Start and Enable Docker

  1. Start Docker Service:
   sudo service docker start
Enter fullscreen mode Exit fullscreen mode
  • Purpose: Manually starts the Docker service, making Docker operational on your WSL environment.
  1. Enable Docker to Start on Boot:
   sudo systemctl enable docker
Enter fullscreen mode Exit fullscreen mode
  • Purpose: Configures Docker to start automatically whenever the WSL environment is launched.

6. (Optional) Allow Non-Sudo Docker Usage

  1. Add User to Docker Group:
   sudo usermod -aG docker $USER
Enter fullscreen mode Exit fullscreen mode
  • Purpose: Adds your user to the Docker group, allowing you to run Docker commands without using sudo.
  • Context: This step is optional but recommended for convenience. After running this command, log out and back in to apply the changes.

7. Verify Installation

  1. Check Docker Version:
   docker --version
Enter fullscreen mode Exit fullscreen mode
  • Purpose: Confirms that Docker is installed correctly by displaying the installed version.
  1. Run a Test Container:
   docker run hello-world
Enter fullscreen mode Exit fullscreen mode
  • Purpose: Runs a test container to verify that Docker is functioning properly within your WSL environment.

Diving to more chaose ...
peace ✌🏾🕊️

. . . . . . . . . . .
Terabox Video Player