Reputation: 35410
Trying to wrap my head around Docker, WSL2, Distros, Images and Containers. What is the difference between a WSL distro and a Docker image? Looking at the following two snapshots, it looks like those are different things:
List of installed distros in WSL:
List of images in Docker Desktop:
Alpine and Ubuntu are listed in the list of additional distros but do not show up in the list of images.
How am I supposed to run one of the installed WSL distros (Alpine or Ubuntu) as a Container and get to its terminal? Lastly, can I launch Ubuntu's desktop UI from within that container?
Upvotes: 1
Views: 10462
Reputation: 20745
Docker images and WSL distributions are two completely different things from the usage standpoint.
In the context of over-simplifying to compare and explain the two:
WSL Distributions contain the tools that you use to interact with and develop applications using Linux. This includes your shell (bash by default in Ubuntu) and the docker
client (provided by Docker Desktop).
Docker images are what you use as a starting point for your Docker containers.
The third screenshot you provided is Settings dialog that allows you to choose which WSL images should be integrated with Docker. Try the following:
docker
commandYou should find it isn't there.
docker
command should now be there.Docker desktop actually injects a link for the docker
command:
docker-desktop
distributionIn general, it's fine just to leave it on for all distributions.
Now I know your next question:
You need to actually pull the Docker images onto your computer first:
docker run --rm -it alpine
Docker will detect that you don't have the Docker Alpine image installed, pull it, and run it. This is a bit of Docker shorthand for two steps, actually:
docker pull alpine
docker run --rm -it alpine
The -it
options are for "interactive" and "terminal".
At this point, you'll be at the BusyBox shell prompt (Alpine's default) that is running inside your Ubuntu WSL distribution.
Before exiting, go back to Docker Desktop and examine the list of containers and images. You'll see:
If you start another terminal with Ubuntu open, you can run:
docker ps
to show you the container informationdocker images
to show you the image informationThis is essentially the same info that you see in Docker Desktop.
Go back to the first Ubuntu WSL2 terminal, which is running the Alpine container with the BusyBox prompt. Try running docker
there -- It won't work, because this is a container based on the Docker Alpine image, not your WSL Alpine distribution.
Type exit
or Ctrl+D to exit that prompt, and you'll now be back at the bash prompt for Ubuntu.
At this point, you'll notice that your Docker container is now gone, since we specified the --rm
option that removes it when the process ends. If we hadn't done that, it would still show as a "Stopped" container in Docker.
You'll find that the Alpine Docker image, however, is still there. Once pulled onto your machine, Docker images stay until you remove them.
Docker images and containers can take a little bit to understand, and I can understand the added confusion in WSL distributions. Play around with them a bit, read some Docker tutorials, and the information above will start to make sense shortly.
Side note: Come back and read this after the above makes sense.
Docker containers and WSL2 distributions shared one big similarity in their architecture, at least -- they are both container technologies, just different.
WSL2 distributions are actually containers running in their own namespace inside the (hidden) WSL2 Hyper-V virtual machine. They share the same kernel and network, but each WSL2 distribution/instance has its own, separate, isolated PID and user namespaces.
This is, at the core, the same concept that Docker containers use. So with WSL2 and Docker, we are really running:
Upvotes: 2