今天讀完 鳥哥的 Linux 私房菜 -- 第六章、Linux 檔案與目錄管理
想用 WSL2 來玩玩看 ubuntu 發生以下問題
先說重點 :
WSL2-docker有兩種模式、WSL2-docker有兩種模式、WSL2-docker有兩種模式
分別是原生 Linux 跟 Window docker destop
預設使用 Window docker destop !! 所以不能用單純 linux 安裝 docker 方式安裝
另外更新補充為何 linux 標準安裝 docker 指令不能使用原因是
注意:不同于完全linux虚拟机方式,WLS2下通过apt install docker-ce命令安装的docker无法启动,因为WSL2方式的ubuntu里面没有systemd。上述官方get-docker.sh安装的docker,dockerd进程是用ubuntu传统的init方式而非systemd启动的。
今天升級 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 ]
WSL2有兩種模式
這有出處嗎
從來沒聽過耶
那是 docker 不是 wsl2
感謝,這是我的錯,我修改 WSL2-docker
另外補充為何 linux 標準安裝 docker 指令不能使用原因是
注意:不同于完全linux虚拟机方式,WLS2下通过apt install docker-ce命令安装的docker无法启动,因为WSL2方式的ubuntu里面没有systemd。上述官方get-docker.sh安装的docker,dockerd进程是用ubuntu传统的init方式而非systemd启动的。