Logo

dev-resources.site

for different kinds of informations.

Docker Installation Log for WSL 2 on Windows

Published at
8/19/2024
Categories
docker
junior
code
wsl
Author
eddiegulay
Categories
4 categories in total
docker
open
junior
open
code
open
wsl
open
Author
10 person written this
eddiegulay
open
Docker Installation Log for WSL 2 on Windows

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 ✌🏾🕊️

wsl Article's
30 articles in total
Favicon
Update WSL Ubuntu password
Favicon
Building OpenCV 4.10.0 with GUI Support in WSL
Favicon
Video: Install Ubuntu using WSL 2
Favicon
Install Zellij on WSL
Favicon
Work from anywhere with VSCode Remote Tunnels
Favicon
SSL verification error at depth 2 - Zscaler | WSL
Favicon
Accelerate 1-bit LLM Inference with BitNet on WSL2 (Ubuntu)
Favicon
Just start using WSL
Favicon
Change WSL/Docker files to another disk
Favicon
Setup your laravel 11 in windows
Favicon
Install Ubuntu on WSL 2
Favicon
How to Install WSL from PowerShell on Windows 10 and 11
Favicon
WSL in AWS Windows Server 2022 Core instance
Favicon
Docker Installation Log for WSL 2 on Windows
Favicon
Enable WSL shell in GitHub Desktop
Favicon
Installing Ruby using rbenv on your WSL Ubuntu system
Favicon
How to Install Redis on Windows Using WSL2
Favicon
PowerShell Development in Neovim
Favicon
WSL: Gerenciando o disco da distro
Favicon
Docker
Favicon
Share Postgresql from Windows to WSL Linux
Favicon
Add Manjaro into WSL 2
Favicon
Using WSL2 as primary driver for 3 months with Fedora
Favicon
Wsl installation error
Favicon
Install Debian in Different Location -WSL Windows
Favicon
Monitor GPU Usage in WSL debian
Favicon
Dicas e configurações para seu sistema linux
Favicon
Instalando de maneira rápida e eficiente suas ferramentas no WSL. Pt-3
Favicon
Arch install azure cli
Favicon
Melhorando e configurando seu novo Shell linux. Pt-2

Featured ones: