How Docker really works in Windows

I am trying to get a better understanding of how Docker works, in Windows 10…This is what I think is going on:

  1. We first download the Docker desktop installer for Windows from the Docker website. After the installation is completed, we run the installed Docker CLI and make sure Docker is installed.

Q: How is the Docker CLI different from the regular CMD shell or Powershell? Is it really just another shell but with some other configurations automatically launched?

Q: Does the Docker desktop installation process automatically install both Hyper V and WSL 2 (which is different from WSL1)? I think Hyper V is a hypervisor to run and manage virtual machines and is WSL2 a lightweight Linux OS virtual machine, correct?? These two components are not needed if the host OS is Linux…What if the host OS is Mac?

  1. Once Docker is successfully installed, we create a python script .py that we plan to dockerize. The docker image must contain the line FROM python :3. This line tells the docker engine to go online to Docker hub and use a parent image that contains the interpreter python (any subversion of version 3:…?) as well as the Linux distribution Alpine, correct? Why do we need that Alpine distro? Don’t we already have WSL2, which is itself a Linux OS, installed on our machine to be able to run image and build containers? I am confused here…

Thank you for any help.

Your question make me almost believe you have an entry in your start menu for “Docker CLI” which opens a terminal… I never had such en entry in the start menu regardless of the Docker Desktop version.

So you must be referring to the docker cli command, which can be used either in CMD, Powershell, or even the git-bash shell to interact with a docker engine. By default it uses the default, which points to the docker enigne that Docker Desktop provides. You can check it with docker context ls.

It has been ages, so I don’t recall the answer to that question.

Correct about Hyper V. Windows Subsystem for Linux provides a Linux VM on a lightweight system vm, and runs wsl2 distributions on that kernel of the system vm. Docker Dekstop will create and manage the utility vm as an appliance with read-only filesystem.

While Docker Desktop always runs the docker engine inside a utility vm (regardless(!) of the OS), Docker CE runs directly on a supported Linux OS.

You already figured out that you need to write a Dockerfile. The FROM instruction could be either an existing base image, or scratch. The later is used to create images like the distro base images, where you just extract a distribution tar.

If the base image exists in your local image cache, the local copy will be used, otherwise the image will be pulled from Docker Hub and added to your local image cache. Base images usually contain a distribution that consists of a minimal set of binaries, libraries and configuration files, but they are not a full os.

Images encapsulate a main application/service, all it dependencies and configurations, and hopefully a more or less clever entrypoint script to prepare the container (like modifying config files) before the main process is started. An images is the delivery artifact and the blueprint for the runtime environment a container created from it.

Your script requires python3. python3 on the other hand is dynamicly compiled against os libraries. Unless there is a python3 release that is static compiled, and therefore does not require any os libraries, there is no way to create a python3 image that does not require a distribution base image that provide the libraries that python3 requires.

The sole purpose of a container is to isolate a process, so it thinks that it runs on its own host, with its own filesystem and its own network. It is not able to see and use anything from the host.

1 Like