Even "docker version" command occur a problem on WSL2 in Windows11

My Windows 11 is localized to Japanese so I translated some Japanese words in English myself.
To post this post, I put double quotations or white space in some words.

Erition Windows 11 Pro
Version 23H2
Installed at ‎2024/‎03/‎31
OS builld 22631.4112
Experience Windows Feature Experience Pack 1000.22700.1034.0

Docker Desktop 4.34.0 (165256) is currently the newest version available.

PS C:\Users\Hoge> wsl --status
Current: Ubuntu
Current version: 2

PS C:\Users\Hoge> wsl -l -v
NAME STATE VERSION

  • Ubuntu Running 2
    docker-desktop Running 2

$ docker compose version
Docker Compose version v2.29.1-desktop.1

$ ls -l /var/run/docker.sock
srw-rw---- 1 root docker 0 Sep 3 06:15 /var/run/docker.sock

I have done:
sudo apt update
sudo apt install docker .io

sudo systemctl start docker
sudo systemctl enable docker

sudo apt install docker-compose

$ dpkg -l | grep docker
ii docker-buildx-plugin 0.16.2-1~ubuntu.22.04~jammy amd64 Docker Buildx cli plugin.
ii docker-ce 5:27.2.0-1~ubuntu.22.04~jammy amd64 Docker: the open-source application container engine
ii docker-ce-cli 5:27.2.0-1~ubuntu.22.04~jammy amd64 Docker CLI: the open-source application container engine
ii docker-ce-rootless-extras 5:27.2.0-1~ubuntu.22.04~jammy amd64 Rootless support for Docker.
ii docker-compose 1.29.2-1 all define and run multi-container Docker applications with YAML
ii docker-compose-plugin 2.29.2-1~ubuntu.22.04~jammy amd64 Docker Compose (V2) plugin for the Docker CLI.
ii python3-docker 5.0.3-1 all Python 3 wrapper to access docke .io’s control socket
ii python3-dockerpty 0.4.1-2 all Pseudo-tty handler for docker Python client (Python 3.x)
rc wmdocker 1.5-2 amd64 System tray for KDE3/GNOME2 docklet applications

$ ls
docker docker-compose.yml src

$ docker compose up -d --build --verbose
unknown flag: --verbose

$ docker version
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x58 pc=0x55b1aad938e0]

goroutine 1 [running]:
github .com/docker/cli/vendor/github.com/docker/docker/client.(*Client).ClientVersion(0xc000138000?)
/go/src/github.com/docker/cli/vendor/github.com/docker/docker/client/client.go:309
github .com/docker/cli/cli/command.(*DockerCli).CurrentVersion(0xc000138000)
/go/src/github.com/docker/cli/cli/command/cli.go:111 +0x30
github .com/docker/cli/cli/command/system.newClientVersion({0xc00013daf0, 0xd}, {0x55b1ab9c7eb8, 0xc000138000})
/go/src/github.com/docker/cli/cli/command/system/version.go:104 +0x1be
github .com/docker/cli/cli/command/system.runVersion({0x55b1ab9bd0f8, 0xc0003b2bc0}, {0x55b1ab9c7eb8, 0xc000138000}, 0xc00039c9f0?)
/go/src/github.com/docker/cli/cli/command/system/version.go:157 +0x8b
github .com/docker/cli/cli/command/system.NewVersionCommand.func1(0x0?, {0x0?, 0x0?, 0x0?})
/go/src/github.com/docker/cli/cli/command/system/version.go:119 +0x30
main.runDocker.(*DockerCli).InstrumentCobraCommands.func4.2(0xc00016a300?, {0x55b1ac2d2360, 0x0, 0x0})
/go/src/github .com/docker/cli/cli/command/telemetry_utils.go:57 +0x6c
github .com/docker/cli/vendor/github .com/spf13/cobra.(*Command).execute(0xc00016a300, {0xc000121af0, 0x0, 0x0})
/go/src/github .com/docker/cli/vendor/github .com/spf13/cobra/command.go:985 +0xabc
github .com/docker/cli/vendor/github .com/spf13/cobra.(*Command).ExecuteC(0xc00013e000)
/go/src/github .com/docker/cli/vendor/github .com/spf13/cobra/command.go:1117 +0x3ff
github .com/docker/cli/vendor/github .com/spf13/cobra.(*Command).Execute(…)
/go/src/github .com/docker/cli/vendor/github .com/spf13/cobra/command.go:1041
github .com/docker/cli/vendor/github .com/spf13/cobra.(*Command).ExecuteContext(…)
/go/src/github .com/docker/cli/vendor/github .com/spf13/cobra/command.go:1034
main.runDocker({0x55b1ab9bd0f8?, 0xc0003b2bc0}, 0xc000138000)
/go/src/github .com/docker/cli/cmd/docker/docker.go:414 +0x974
main.dockerMain()
/go/src/github .com/docker/cli/cmd/docker/docker.go:50 +0x1f9
main.main()
/go/src/github .com/docker/cli/cmd/docker/docker.go:32 +0x13

$ docker ps
Failed to initialize: protocol not available

I have asked Cloud3 many times already, but no solutions…

If you are using Windows, you can use Docker Desktop and enable WSL2 integration so you can use a docker client in that distribution without installing it. You don’t need to install Docker in the WSL2 distributions, especially not the docker.io package which is not the official Docker CE.

Uninstall everything you installed in the WSL2 distribution for Docker and enable WSL integration in Docker Desktop. If you installed too many things it could be easier to delete the WSL distribution and recreate it.