Docker Desktop on Windows with WSL (Ubuntu)

On Windows with Docker Desktop + WSL2, all Docker containers, images, and volumes are stored inside the WSL2 backend, not directly on your Windows filesystem.

Here’s how it works:


1️⃣ Where Docker stores containers and images

  • Docker Desktop uses a special WSL2 distro called:

docker-desktop
docker-desktop-data
  • When you run a container:

docker run hello-world
  • It is actually running inside the docker-desktop WSL2 instance, not Ubuntu or C:\ directly.

  • All container filesystem layers, images, and volumes are stored inside this docker-desktop-data virtual disk (ext4.vhdx) located somewhere like:

C:\Users\kr28n\AppData\Local\Docker\wsl\data\ext4.vhdx

2️⃣ Interaction with Ubuntu distro

  • Your Ubuntu WSL (/home/kr28n) can access Docker CLI because Docker Desktop exposes the engine to WSL distros.

  • But containers don’t live inside your Ubuntu filesystem; they live in the docker-desktop backend.

  • Ubuntu just acts as a client to Docker.


3️⃣ How to verify

docker info

You’ll see:

Server:
 Containers: 1
  Running: 1
 Images: 1
 Storage Driver: overlay2
 ...
  • Server = docker engine running inside WSL2 (docker-desktop)

  • Storage Driver: overlay2 = container filesystem inside virtual disk


4️⃣ Accessing container files

  • You can copy files to/from containers from Ubuntu using:

docker cp <container_id>:/path/in/container /home/kr28n/
docker cp /home/kr28n/myfile.txt <container_id>:/path/in/container
  • But the container’s filesystem itself is inside docker-desktop virtual disk, not Ubuntu home.


✅ TL;DR

  • Docker containers never live in Ubuntu /home or C:\Users directly.

  • They live in docker-desktop WSL distro (docker-desktop-data).

  • Ubuntu WSL is just a client that talks to Docker engine.

  • You can access files via docker cp or mount Windows/Ubuntu directories into containers when needed.


With Docker Desktop on Windows using WSL2 backend, you can run Docker commands from both Windows and Ubuntu. Here’s how it works:


1️⃣ From Windows (PowerShell / CMD)

docker version
docker run hello-world
docker ps -a
  • The Docker CLI in Windows communicates with Docker engine in WSL2 (docker-desktop distro).

  • Everything is executed inside the WSL2 Linux environment automatically.


2️⃣ From Ubuntu WSL

Open Ubuntu and run:

docker version
docker run hello-world
docker ps -a
  • Ubuntu WSL sees the same Docker engine because Docker Desktop exposes the engine to all WSL distros.

  • Containers and images are the same as when you run Docker from Windows.


3️⃣ Notes / Tips

ThingBehavior
ContainersSingle set shared between Windows CLI and Ubuntu CLI
ImagesSame images accessible from both environments
VolumesSame volumes accessible
Path mountsYou can mount /mnt/c/... from Ubuntu into containers, just like Windows paths from Windows CLI
PermissionsLinux permissions matter when mounting Linux paths from Ubuntu

4️⃣ Quick check

Run on both Windows and Ubuntu:

docker ps -a
docker images
docker run --rm -it alpine sh
  • You will see the same containers/images.

  • This proves Docker engine is shared, not duplicated.


✅ TL;DR

  • Yes, you can run Docker commands from:

    • Windows CMD / PowerShell

    • Ubuntu WSL shell

  • All commands talk to the same Docker engine inside docker-desktop WSL distro.


Below is a small diagram showing Docker CLI in Windows + Ubuntu → shared Docker engine → containers/images so it’s easy to visualize.

             ┌─────────────────────────────┐
             │       Windows Host          │
             │                             │
             │  CMD / PowerShell / VSCode  │
             │  docker CLI works here      │
             └─────────────┬───────────────┘
                           │
                           │ communicates via WSL integration
                           ▼
             ┌─────────────────────────────┐
             │       WSL 2 Backend        │
             │  docker-desktop distro      │
             │  docker engine runs here    │
             └─────────────┬───────────────┘
                           │
                           │ shared filesystem
                           ▼
             ┌─────────────────────────────┐
             │     Ubuntu WSL Distro       │
             │  docker CLI works here      │
             │  /home/kr28n (Linux files) │
             └─────────────┬───────────────┘
                           │
           ┌───────────────┴───────────────┐
           │       Linux / Windows Files    │
           │  Ubuntu: /home/kr28n          │
           │  Windows: /mnt/c/Users/kr28n  │
           └───────────────────────────────┘

✅ Key points

  1. Docker engine lives in docker-desktop WSL distro.

  2. CLI commands can be run from Windows or Ubuntu — they talk to the same engine.

  3. Containers/images are shared across both environments.

  4. Ubuntu home (/home/kr28n) is inside WSL virtual disk; Windows files are accessible under /mnt/c/....

  5. Use \\wsl$\Ubuntu\home\kr28n to access Linux home from Windows Explorer.



Comments

Popular posts from this blog

Docker Command