iT邦幫忙

1

WSL2 安裝完 docker 後執行 sudo service docker restart`出現 docker: unrecognized service 錯誤

  • 分享至 

  • xImage

今天升級 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

xxx


更新

我的 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
結果 : 無效

xxx

$ 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 ]

看更多先前的討論...收起先前的討論...
dragonH iT邦超人 5 級 ‧ 2020-09-07 10:42:41 檢舉
你是用 ubuntu 嗎

你是怎麼裝 docker的
您好,我更新在內文了
https://blog.csdn.net/phpzhi/article/details/106990847
是這個問題嗎
您好,嘗試過,不行,更新在內文了
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中
3
dragonH
iT邦超人 5 級 ‧ 2020-09-07 11:12:39
最佳解答

官網的裝

不要直接用 apt install docker.io

我照官網裝在 18.04 跟 20.04 都成功

您好大神,感謝!
這個是 windows docker destop 的解決方式
我上面有另外更新 原生 linux docker 解決方式

dragonH iT邦超人 5 級 ‧ 2020-09-07 13:22:20 檢舉

呃 我就是在 wsl2 的 ubuntu 裝的

0
drewbinsky
iT邦見習生 ‧ 2023-04-18 15:41:07

這個錯誤可能是由於 ovo game Docker 服務未能正確安裝而導致的。請檢查您的 Docker 安裝是否正確,或者嘗試重新安裝 Docker。您可以在 Docker 的官方網站上找到有關 Docker 安裝和設置的更多信息。

0
raderphy
iT邦見習生 ‧ 2024-03-07 11:13:18

服務未能裝而導致的。您的 裝是否正確,安裝 的官方網站上找關和設置信息。
spacebar clicker

0
sarahlison
iT邦見習生 ‧ 2024-05-16 11:30:07

不正確的安裝會導致意想不到的錯誤。 再次檢查並執行每一步 bob the robber

0
lillianthu
iT邦見習生 ‧ 2024-06-27 03:22:49

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

0
leque12634
iT邦見習生 ‧ 2024-11-21 17:02:58

Step into the world of Retro Bowl , where football fans can enjoy a delightful blend of strategy and action. Manage your own team, make tactical decisions, and aim for championship glory.

我要發表回答

立即登入回答