今天升級 WSL2 安裝完 docker 後執行sudo service docker restart
出現 docker: unrecognized service
完整 cmd 如下
$ sudo service docker restart
[sudo] password for sa:
docker: unrecognized service
$ docker -v
Docker version 19.03.8, build afacb8b7f0
更新
我的 ubuntu 是從 windows store 安裝 , 版本是20.04
$ cat /etc/*release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.1 LTS"
NAME="Ubuntu"
VERSION="20.04.1 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.1 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
安裝 docker 命令
sudo apt update
sudo apt upgrade
sudo apt install docker.io
嘗試1 : 按照此網站 https://blog.csdn.net/phpzhi/article/details/106990847
結果 : 無效
$ sudo rm -rf /var/lib/docker-desktop/
$ sudo service docker start
docker: unrecognized service
嘗試2 : 按照此網頁 win10利用WSL2安装docker的2种方式 - 知乎
結果 : 成功
分析 :
WSL2 預設建議使用 windows docker desktop 而非原生 linux docker,所以需要另外下載 windows docker desktop...(坑! 我就是不想要 docker desktop 才用 WSL 或 VM阿)
假如要用原生linux請使用以下script
$ curl -fsSL https://get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh
$ sudo service docker start
完整過程
$ curl -fsSL https://get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh
[sudo] password for sa:
# Executing docker install script, commit: 26ff363bcf3b3f5a00498ac43694bf1c7d9ce16c
Warning: the "docker" command appears to already exist on this system.
If you already have Docker installed, this script can cause trouble, which is
why we're displaying this warning and provide the opportunity to cancel the
installation.
If you installed the current Docker package using this script and are using it
again to update Docker, you can safely ignore this message.
You may press Ctrl+C now to abort this script.
+ sleep 20
WSL DETECTED: We recommend using Docker Desktop for Windows.
Please get Docker Desktop from https://www.docker.com/products/docker-desktop
You may press Ctrl+C now to abort this script.
+ sleep 20
+ sh -c apt-get update -qq >/dev/null
+ sh -c DEBIAN_FRONTEND=noninteractive apt-get install -y -qq apt-transport-https ca-certificates curl >/dev/null
+ sh -c curl -fsSL "https://download.docker.com/linux/ubuntu/gpg" | apt-key add -qq - >/dev/null
Warning: apt-key output should not be parsed (stdout is not a terminal)
+ sh -c echo "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable" > /etc/apt/sources.list.d/docker.list
+ sh -c apt-get update -qq >/dev/null
+ [ -n ]
+ sh -c apt-get install -y -qq --no-install-recommends docker-ce >/dev/null
+ sh -c docker version
Client: Docker Engine - Community
Version: 19.03.12
API version: 1.40
Go version: go1.13.10
Git commit: 48a66213fe
Built: Mon Jun 22 15:45:44 2020
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.12
API version: 1.40 (minimum version 1.12)
Go version: go1.13.10
Git commit: 48a66213fe
Built: Mon Jun 22 15:49:27 2020
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: v1.2.13
GitCommit: 7ad184331fa3e55e52b890ea95e65ba581ae3429
runc:
Version: 1.0.0-rc10
GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd
docker-init:
Version: 0.18.0
GitCommit: fec3683
If you would like to use Docker as a non-root user, you should now consider
adding your user to the "docker" group with something like:
sudo usermod -aG docker your-user
Remember that you will have to log out and back in for this to take effect!
WARNING: Adding a user to the "docker" group will grant the ability to run
containers which can be used to obtain root privileges on the
docker host.
Refer to https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface
for more information.
$ sudo service docker start
* Starting Docker: docker [ OK ]
這個錯誤可能是由於 ovo game Docker 服務未能正確安裝而導致的。請檢查您的 Docker 安裝是否正確,或者嘗試重新安裝 Docker。您可以在 Docker 的官方網站上找到有關 Docker 安裝和設置的更多信息。
The issue "Docker: unrecognized service" in WSL2 often occurs because WSL2 doesn't fully support system services like systemd, making it challenging to start services using service or systemctl.blob opera