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
- Install WSL (Windows Subsystem for Linux):
wsl --install
- 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.
-
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.
Set WSL 2 as the Default Version:
wsl --set-default-version 2
- Purpose: Ensures that new WSL instances use WSL 2, which offers improved performance and full system call compatibility.
-
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
- Update Package Information:
sudo apt update && sudo apt upgrade
- 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.
- Install Required Packages:
sudo apt install apt-transport-https ca-certificates curl software-properties-common
-
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
- Add Docker GPG Key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
- 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.
- 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
-
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
- Install Docker Engine and Related Tools:
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io
- 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
anddocker ps
. - containerd.io: A container runtime that manages the lifecycle of containers, responsible for running and supervising containers.
5. Start and Enable Docker
- Start Docker Service:
sudo service docker start
- Purpose: Manually starts the Docker service, making Docker operational on your WSL environment.
- Enable Docker to Start on Boot:
sudo systemctl enable docker
- Purpose: Configures Docker to start automatically whenever the WSL environment is launched.
6. (Optional) Allow Non-Sudo Docker Usage
- Add User to Docker Group:
sudo usermod -aG docker $USER
-
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
- Check Docker Version:
docker --version
- Purpose: Confirms that Docker is installed correctly by displaying the installed version.
- Run a Test Container:
docker run hello-world
- Purpose: Runs a test container to verify that Docker is functioning properly within your WSL environment.
Diving to more chaose ...
peace ✌🏾🕊️