Search code examples
dockerwindows-subsystem-for-linuxdocker-desktop

Where do "host" in docker-desktop refer to?


I'm trying to create a container with Docker API.

My environment is as follow:

  • Windows 11 (I guess it should run in windows 10 as well)
  • Docker desktop version v20.10.8 with the following setting checked:
    • WS2 Based Engine
    • Expose daemon on tcp://localhost:2375 without TLS

My curl request is as follow:

curl --location --request POST 'http://localhost:2375/v1.41/containers/create?name=oraumum' \
--header 'Content-Type: application/json' \
--data-raw '{
  "Image": "nginx",
  "Volumes": {
    "/volumes/data": { }
  },
  "ExposedPorts": {
    "80/tcp": {}
  },
  "HostConfig": {
    "PortBindings": {
      "80/tcp": [
        {
          "HostPort": "5000"
        }
      ]
    },
    "RestartPolicy": {
      "Name": "always"
    },
    "Mounts": [
        {
           "Target":   "/test",
           "Source":   "/",
           "Type":     "bind", 
           "ReadOnly": false
        }
     ]
  }
}'

In this experiment, I try to load the / of the host into /test in my container.

Strangely, I find that Mount's Source is neither my WSL nor windows machine:

docker exec -it oraumum bash
# ls
bin   dev                  docker-entrypoint.sh  home  lib64  mnt  proc  run   srv  test  usr  volumes
boot  docker-entrypoint.d  etc                   lib   media  opt  root  sbin  sys  tmp   var
# cd /test
# ls
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
# ls /home
# ls -al /home
total 8
drwxr-xr-x 2 root root 4096 Jun 13 10:30 .
drwxr-xr-x 1 root root 4096 Sep 12 13:46 ..
#

What actually happened here? Is this related to hyper-V or something?

UPDATE: My WSL2's home is not empty:

gofrendi@DESKTOP-MEO4ER4 [21:26:02] [/home]
-> % pwd
/home
gofrendi@DESKTOP-MEO4ER4 [21:26:07] [/home]
-> % ls -al
total 12
drwxr-xr-x  3 root     root     4096 Sep 10 08:17 .
drwxr-xr-x 19 root     root     4096 Sep 12 17:18 ..
drwxr-xr-x 24 gofrendi gofrendi 4096 Sep 12 21:26 gofrendi
gofrendi@DESKTOP-MEO4ER4 [21:26:12] [/home]

Solution

  • Answering my own question here: What actually happened.

    When you activate the WSL2 backend engine in your docker-desktop, it will create 2 different storage (and presumably 2 different VMs as well).

    Beside my default WSL VM (the Ubuntu one), Docker-desktop also created docker-desktop and docker-desktop-data.

    The mount source is probably located on docker-desktop or docker-desktop-data.

    enter image description here