Docker / Installing Docker
Setting Up Docker on WSL 2
In this tutorial, you'll learn how to set up Docker on Windows Subsystem for Linux (WSL) 2. WSL 2 provides a full compatibility layer for running Linux software on Windows and can…
Section overview
5 resourcesExplains how to install Docker on different operating systems.
1. Introduction
In this tutorial, our goal is to set up Docker on the Windows Subsystem for Linux (WSL) 2. Docker is a platform that allows you to develop, test, and deliver applications quickly. The WSL 2 is a compatibility layer for running Linux binary executables natively on Windows 10 and Windows Server 2019.
By the end of this tutorial, you will learn how to install Docker on WSL 2, run Docker commands, and manage Docker containers and images.
The prerequisites for this tutorial are:
- Basic understanding of Docker and WSL.
- You should have WSL 2 installed on your Windows machine.
2. Step-by-Step Guide
Install Docker Desktop on Windows
-
Download Docker Desktop for Windows from Docker Hub. This will automatically include Docker engine, Docker CLI client, Docker Compose, Docker Machine, and Kitematic.
-
Once you've downloaded Docker Desktop, double-click on the downloaded
.exefile to start the installation. Accept the terms of the service, authorize the installer, and proceed with the install. -
After installing Docker Desktop, you need to enable the WSL 2 based engine. Open Docker Desktop, go to
Settings > General, check theUse the WSL 2 based engineoption and apply the changes.
Set Docker to Use WSL 2
-
Open your WSL 2 terminal and check the installed distributions by running
wsl -l -v. -
Set the desired distribution to use WSL 2 if it's not already set. You can do this by running
wsl --set-version <distribution> 2. Replace<distribution>with the name of your distribution.
3. Code Examples
Example 1: Run Docker Version Command
To check if Docker is working correctly, run the Docker version command in your WSL 2 terminal.
$ docker --version
You should get an output similar to this:
Docker version 20.10.5, build 55c4c88
Example 2: Run a Docker Container
Here's an example of running a simple Docker container. We will use the hello-world image.
$ docker run hello-world
This command will download the hello-world Docker image (if it isn't available locally), create a new container from that image, and run the container.
The output will be a message from the Hello World application:
Hello from Docker!
This message shows that your installation appears to be working correctly.
...
4. Summary
In this tutorial, we learned how to set up Docker on WSL 2. We installed Docker Desktop on Windows, enabled the WSL 2 based engine, checked the Docker version, and ran a Docker container.
Next, you can learn about building your own Docker images, pushing images to Docker Hub, and managing Docker networks and volumes.
Some additional resources for learning include the official Docker documentation, Docker's getting started guide, and various online courses on platforms like Coursera and Udemy.
5. Practice Exercises
Exercise 1: Pull the nginx Docker image and run a container from it.
Solution:
$ docker pull nginx
$ docker run -d -p 8080:80 nginx
The docker pull command downloads the nginx image, and the docker run command starts a new container from the nginx image. The -d option starts the container in detached mode (in the background), and -p 8080:80 maps port 8080 on the host to port 80 on the container.
Exercise 2: List all Docker containers and stop a running container.
Solution:
$ docker ps
$ docker stop <container-id>
The docker ps command lists all running Docker containers, and docker stop stops a running container. You need to replace <container-id> with the ID of the container you want to stop.
Tips for further practice: Try running different Docker images, managing multiple containers, and using Docker Compose to manage multi-container applications.
Need Help Implementing This?
We build custom systems, plugins, and scalable infrastructure.
Related topics
Keep learning with adjacent tracks.
Popular tools
Helpful utilities for quick tasks.
Random Password Generator
Create secure, complex passwords with custom length and character options.
Use toolLatest articles
Fresh insights from the CodiWiki team.
AI in Drug Discovery: Accelerating Medical Breakthroughs
In the rapidly evolving landscape of healthcare and pharmaceuticals, Artificial Intelligence (AI) in drug dis…
Read articleAI in Retail: Personalized Shopping and Inventory Management
In the rapidly evolving retail landscape, the integration of Artificial Intelligence (AI) is revolutionizing …
Read articleAI in Public Safety: Predictive Policing and Crime Prevention
In the realm of public safety, the integration of Artificial Intelligence (AI) stands as a beacon of innovati…
Read articleAI in Mental Health: Assisting with Therapy and Diagnostics
In the realm of mental health, the integration of Artificial Intelligence (AI) stands as a beacon of hope and…
Read articleAI in Legal Compliance: Ensuring Regulatory Adherence
In an era where technology continually reshapes the boundaries of industries, Artificial Intelligence (AI) in…
Read article