Search code examples
dockervirtualization

why docker instances can run on both windows and linux machine without the need of VM?


I'm a newbie to docker. I know the key difference between Docker and VM is, containers share the host's operation system while VM requires a seperate operation systems.

But I saw some images which can produces containers that can be running on both Windows and Linux machine without the need of VM. But how does it work? Let's say I am using windows operating systems on my machine and runs a Linux container, how does windows OS provide the Linux's Kernel to the running app in the container?

btw, if windows can run linux containers, then does it mean that we as users can use all the tools that were previously exclusive to linux as long as the software companies create a image for the tool?


Solution

  • When running on Windows, recent versions of Docker use WSL2, which uses a lightweight virtual machine:

    WSL 2 uses the latest and greatest in virtualization technology to run a Linux kernel inside of a lightweight utility virtual machine (VM).

    As such, when using docker, you are actually running a full Linux kernel in a VM, despite the transparent experience. When you run a container, it is actually a container inside that VM.