Setting Up Docker with WSL¶
1. Install and Configure WSL¶
Enable WSL Features¶
Open the command line as administrator and run the following commands to enable WSL features:
Install the Linux Kernel Update Package¶
Download and install the latest Linux kernel update package from Microsoft:
After installation, restart Windows.
Set WSL to Version 2¶
Run the following command as administrator to set WSL to version 2:
Restart Windows again to apply the changes.
2. Enable Systemd in WSL¶
Check WSL Version¶
Ensure you are running WSL version 0.67.6
or higher. Check your version with:
If the command fails, upgrade to the Microsoft Store version of WSL. Run the following command to update:
Alternatively, download the latest release from the:¶
Configure Systemd¶
Edit the wsl.conf
file to enable systemd. Open the file with sudo privileges:
Add the following lines:
Save and exit the editor (CTRL+O
, then CTRL+X
).
Restart WSL¶
Close your WSL instance and run the following command in PowerShell to restart WSL:
Launch your WSL instance again and verify systemd is running:
For more details, refer to the official blog post.
3. Install Docker and Docker Compose v2 in WSL 2¶
Install Docker¶
Run the following commands to install Docker:
Add Your User to the Docker Group¶
Add your user to the Docker group to avoid using sudo
with Docker commands:
Verify Installation¶
Check that Docker and Docker Compose were installed successfully:
4. Additional Step for Ubuntu 22.04 or Debian 10+¶
If you're using Ubuntu 22.04 or Debian 10+, configure iptables
for compatibility:
Select option 1
to use iptables-legacy
.
Start Docker¶
Start the Docker service:
Check the status of Docker:
Note: You may need to reboot Windows or restart WSL after applying the
iptables
configuration to ensure networking inside your containers works correctly.