Go to content
The Codest
  • About Us
  • Services
  • Our Team
  • Case studies
    • Blog
    • Meetups
    • Webinars
    • Resources
Careers Get in touch
  • About Us
  • Services
  • Our Team
  • Case studies
    • Blog
    • Meetups
    • Webinars
    • Resources
Careers Get in touch
2020-01-21
Software Development

Painless way to WSL 2 with Docker

Lukasz Kolko

Painless way to WSL 2 with Docker - Image

By introducing the Windows Subsystem for Linux (WSL), Microsoft gave the opportunity for developers to run a GNU/Linux environment directly on Windows, unmodified, without the overhead of a virtual machine. This is a great solution because a lot of developers use one system for programming and another for entertainment.

WSL is still being developed, but it is currently suitable for modern software development, both in the first and the second version. Browsing through the problems and questions reported on the internet, most of them seem to concern the integration of WSL with Docker, especially when it comes to upgrading from WSL 1 to WSL 2.

This article will dispel all ambiguities and help you get through this process painlessly. If you don't have WSL 1 and you want to have WSL 2 with Docker, you can jump straight to the last chapter.

What will you gain?

- Real latest stable Linux kernel (tuned by Microsoft). WSL 1 has a Linux-compatible kernel interface without the Linux kernel code.

- Increased file IO performance. Up to 20x faster compared to WSL 1 when unpacking a zipped tarball, around 2-5x faster when using git clone, npm install and cmake on various projects.

- Full System Call Compatibility. Linux binaries use system calls to perform many functions, such as accessing files, requesting memory, creating processes, and many more. While WSL 1 used a translation layer built by the WSL team, WSL 2 includes its own Linux kernel with full system call compatibility.

- Files stored in a native ext4 partition on a virtual disk.

- Very easy way to integrate with Docker.

I think for most users the file IO performance and easy docker integration sound like sufficient reasons.

Let's go!

I assume you have the latest stable version of Windows 10 Pro. As for today, it is the 1909 release.

Join Windows insiders

Currently, WSL 2 is only available for Windows 10 in insiders’ slow ring. As far as I know, the stable version should be available in May 2020 (20H1 release). The slow ring is quite a safe solution for users who want to have new features a little earlier, already pre-tested by fast ring users. The slow ring gets system updates up to once or twice a month. You can read about insiders release changes in the Microsoft document called Flight Hub.

To join, simply follow the official Microsoft guide. It's very easy and takes up about 15 minutes without losing any personal data.

Upgrade WSL 1 to WSL 2

Follow the official guide. It is also very easy, a couple of shell commands and here you are! Depending on how extensive your Linux under WSL 1 was, this may take some time. Unfortunately, Microsoft has not placed a progress bar or information about the required time, so just be patient.

Cleaning up

This is the most important part for proper cooperation of WSL 2 and Docker. After upgrading to WSL 2, many users are trying to force their version of Docker to cooperate without realizing that Docker team, especially for WSL 2, has prepared a release that will do everything for us. This is the last release of the Docker Edge version (their beta name) – “Docker Desktop WSL 2 backend”. This version, 2.1.7.0, is a well-polished and is a candidate for the upcoming stable release.

Users who didn't have WSL 1 or just installed a fresh version of WSL 2 are lucky and can immediately skip to the last chapter.

If you haven't cleaned your Docker (at all or correctly) and haven't installed the proper version of Docker for WSL 2, you may encounter some common errors, e.g., Cannot connect to the Docker daemon at tcp://localhost:2375“, “Is the Docker daemon running, etc. In most cases, you will lose time if you do not know that you must take a new approach in trying to resolve these errors. To do this, you must first completely remove Docker from WSL and Windows, which is not an obvious step.

The most common example of unremoved remains is the old Docker approach to set the environment variable DOCKER_HOST=tcp://localhost:2375 under WSL 1 for cooperating with Windows Docker option Expose daemon on tcp://localhost:2375 without TLS.

How to completely remove Docker from WSL (Ubuntu)?

  1. As the official Docker docs say:

sudo apt-get remove docker docker-engine docker.io containerd runc

For sure, you can add to this list docker-ce and docker-ce-cli.

  1. Identify all docker packages that you have with dpkg -l | grep -i docker and remove if any still exist.
  2. Remove all residues:
sudo rm -rf /var/lib/docker /etc/docker /etc/apparmor.d/docker /var/run/docker.sock /usr/local/bin/docker-compose /etc/docker

sudo groupdel docker ~/.docker

  1. This step is for advanced users, so be careful. Probably you don't need to make it.

Find all docker word occurrences and remove the ones you are sure of.

sudo find / -name "*docker*"

  1. Check the content of all files below for docker occurrences like ex. environment variable DOCKER_HOST=tcp://localhost:2375.

You can edit these files with the Nano editor, nano ~/.bashrc, or Visual Studio Code, code ~/.bashrc.

~/.bashrc
~/.bash\_aliases
~/.bash\_profile
~/.bash\_login
~/.profile
/etc/bash.bashrc
/etc/profile

How to completely remove Docker from Windows?

  1. Uninstall in normal way with Windows Apps and features panel.
  2. Remove all below if exists:
C:\\Program Files\\Docker
C:\\ProgramData\\DockerDesktop
C:\\Users\\\[USERNAME\]\\.docker
C:\\Users\\\[USERNAME\]\\AppData\\Local\\Docker
C:\\Users\\\[USERNAME\]\\AppData\\Roaming\\Docker
C:\\Users\\\[USERNAME\]\\AppData\\Roaming\\Docker Desktop

What’s next?

Install the latest version of Docker Desktop Edge from here and follow the steps from the official docs. It really comes down to a few clicks.

If everything goes well, you should have your  output from wsl -l -v like this:

  NAME                   STATE           VERSION
  Ubuntu-18.04           Running         2
  docker-desktop         Running         2
  docker-desktop-data    Running         2

That's all. Docker has created its own WSL containers docker-desktop and docker-desktop-data. Some of the available tutorials or advices can be confusing because this time you shouldn't install or configure anything related to Docker under your WSL Linux distribution. It's very important to remember. After the cleaning, it should work well right away.

Additionally..

Setting up WSL 2 with Docker can be a painless process with a few simple steps. Begin by updating package lists using the command "sudo apt-get update" to ensure you have the latest version information. Resolve any missing dependencies with "sudo apt-get install -y build-essential" for a smooth installation experience. Install Docker Engine with "sudo apt-get install -y docker-engine" to effortlessly build, run, and manage containers. Execute "sudo docker run" followed by the image name to launch containers. To keep your environment optimized, periodically run "sudo docker system prune" to remove unused containers and free up disk space. With these steps, you can enjoy the seamless integration of WSL 2 and Docker for efficient containerization in your development workflow.

Related articles

Software Development

3 Useful HTML Tags You Might Not Know Even Existed

Nowadays, accessibility (A11y) is crucial on all stages of building custom software products. Starting from the UX/UI design part, it trespasses into advanced levels of building features in code. It provides tons of benefits for...

Jacek Ludzik
Software Development

5 examples of Ruby’s best usage

Have you ever wondered what we can do with Ruby? Well, the sky is probably the limit, but we are happy to talk about some more or less known cases where we can use this powerful language. Let me give you some examples.

Pawel Muszynski
Software Development

Maintaining a Project in PHP: 5 Mistakes to Avoid

More than one article has been written about the mistakes made during the process of running a project, but rarely does one look at the project requirements and manage the risks given the technology chosen.

Sebastian Luczak
Software Development

5 reasons why you will find qualified Ruby developers in Poland

Real Ruby professionals are rare birds on the market. Ruby is not the most popular technology, so companies often struggle with the problem of finding developers who have both high-level skills and deep experience; oh, and by the...

Jakub
Software Development

9 Mistakes to Avoid While Programming in Java

What mistakes should be avoided while programming in Java? In the following piece we answers this question.

Rafal Sawicki
Software Development

A quick dive into Ruby 2.6. What is new?

Released quite recently, Ruby 2.6 brings a bunch of conveniences that may be worth taking a glimpse of.  What is new? Let’s give it a shot!

Patrycja Slabosz

Subscribe to our knowledge base and stay up to date on the expertise from industry.

About us

We are an agile software development company dedicated to empowering our clients' digital transformation projects and ensuring successful IT project delivery.

    United Kingdom - Headquarters

  • Office 303B, 182-184 High Street North E6 2JA London, England

    Poland - Local Tech Hubs

  • Business Link High5ive, Pawia 9, 31-154 Kraków, Poland
  • Brain Embassy, Konstruktorska 11, 02-673 Warsaw, Poland
  • Aleja Grunwaldzka 472B, 80-309 Gdańsk, Poland

    The Codest

  • Home
  • About us
  • Services
  • Case studies
  • Know how
  • Careers

    Services

  • PHP development
  • Java development
  • Python development
  • Ruby on Rails development
  • React Developers
  • Vue Developers
  • TypeScript Developers
  • DevOps
  • QA Engineers

    Resources

  • What are top CTOs and CIOs Challenges? [2022 updated]
  • Facts and Myths about Cooperating with External Software Development Partner
  • From the USA to Europe: Why do American startups decide to relocate to Europe
  • Privacy policy
  • Website terms of use

Copyright © 2022 by The Codest. All rights reserved.

We use cookies on the site for marketing, analytical and statistical purposes. By continuing to use, without changing your privacy settings, our site, you consent to the storage of cookies in your browser. You can always change the cookie settings in your browser. You can find more information in our Privacy Policy.