junshi356
junshi356

Reputation: 45

Why is docker daemon not running as a service under WSL2 Ubuntu with docker-desktop?

I'm a beginner of docker, and I've set up docker environment in WLS2 Ubuntu distribution with docker-desktop according to https://learn.microsoft.com/en-us/windows/wsl/tutorials/wsl-containers

I tried to use "--api-cors-header" so that I can communicate with docker daemon via RESTful requests from my host machine(windows 10), but I can't run "service dockerd stop" to stop(and restart) docker daemon even if I can use "docker images" to list my images.

me@DESKTOP-PTHS660:~$ service dockerd stop
dockerd: unrecognized service

me@DESKTOP-PTHS660:~$ docker images
REPOSITORY                                                     TAG       IMAGE ID       CREATED         SIZE
ubuntu                                                         14.04     13b66b487594   16 months ago   197MB

When using "ps -ef" to listing processes running in my WSL2 Ubuntu distribution, I can't find dockerd running too. Then which process is responding to my Ubuntu command line commands?

me@DESKTOP-PTHS660:~$ ps -ef
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 22:41 ?        00:00:00 /init
root       128     1  0 22:41 ?        00:00:00 /init
root       129   128  0 22:41 ?        00:00:00 /init
root       130   129  0 22:41 pts/0    00:00:00 /mnt/wsl/docker-desktop/docker-desktop-user-distro proxy --distro-name U
root       143   128  0 22:42 ?        00:00:00 /init
me         144   143  0 22:42 pts/1    00:00:00 docker serve --address unix:///home/me/.docker/run/docker-cli-api.so
root       161     1  0 22:42 ?        00:00:00 /init
root       162   161  0 22:42 ?        00:00:00 /init
me         163   162  0 22:42 pts/2    00:00:00 -bash
me         360   163  0 22:49 pts/2    00:00:00 ps -ef

Upvotes: 0

Views: 2360

Answers (1)

NotTheDr01ds
NotTheDr01ds

Reputation: 20752

Docker Desktop runs a separate "managed" (a.k.a. "don't touch this" ;-)) WSL2 distribution with the Docker Engine, which you can see with wsl -l -v:

  NAME                   STATE           VERSION
* Tumbleweed             Stopped         2
...
  Ubuntu-22.04           Running         2
  Artix-dinit            Stopped         2
  docker-desktop         Stopped         2
  docker-desktop-data    Stopped         2
...

The docker-desktop distribution is what runs the actual Docker Engine daemon, with the docker command itself symlinked in from that distribution. To see that, in your Ubuntu distribution, run:

> ls -lah $(which docker)
lrwxrwxrwx 1 root root 48 Jul 25 12:42 /usr/bin/docker -> /mnt/wsl/docker-desktop/cli-tools/usr/bin/docker*

While I haven't tried this myself, you can configure special options for the Docker Engine daemon (like api-cors-header) via the Docker Desktop settings. Navigate in Settings -> Docker Engine and modify the configuration file per the doc to add the api-cors-header setting.

Upvotes: 2

Related Questions