前言
WSL就是個(gè)坑!
WSL就是個(gè)坑!
WSL就是個(gè)坑!
我第一次安裝使用 Ubuntu 還是第一臺(tái)筆記本,裝了雙系統(tǒng),版本是18.04 LTS,但是我那個(gè)時(shí)候只有機(jī)械硬盤,因此 Ubuntu 桌面十分的卡。
兜兜轉(zhuǎn)轉(zhuǎn),大三的時(shí)候發(fā)現(xiàn)微軟的 WSL2 很好用,想裝一個(gè)學(xué)習(xí) Linux,當(dāng)然選擇了那個(gè)時(shí)候最新的 Ubuntu 22.04 LTS。最近工作需要,學(xué)習(xí)一些 docker 知識(shí)。于是打算在WSL上安裝docker,期間踩了一些坑,在這里記錄下吧。
安裝
使用 Docker 倉庫進(jìn)行安裝
更新 apt 包索引
$ sudo apt-get update
安裝 apt 依賴包,用于通過HTTPS來獲取倉庫
$ sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
添加 Docker 的官方 GPG 密鑰
$ curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
使用以下指令設(shè)置穩(wěn)定版?zhèn)}庫
$ sudo add-apt-repository \
"deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/ \
$(lsb_release -cs) \
stable"
安裝后,輸出如圖:
安裝 Docker Engine-Community
我這里直接安裝最新版本的 Docker Engine-Community 和 containerd,
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
輸出如圖:
到這里基本就安裝完了,試試輸入以下指令運(yùn)行你的第一個(gè)容器:
sudo docker run hello-world
運(yùn)行輸出如下:
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
問題
docker指令必須用sudo執(zhí)行
默認(rèn)情況下, Unix 套接字 (Unix socket)由用戶 root 擁有,其他用戶只能使用 sudo 訪問它。 Docker 守護(hù)進(jìn)程始終以 root 用戶身份運(yùn)行。
為了避免每次都加sudo,需要給現(xiàn)在的賬戶添加docker權(quán)限
創(chuàng)建docker用戶組
$ sudo groupadd docker
添加當(dāng)前用戶到docker用戶組
$ sudo usermod -aG docker $USER
退出當(dāng)前shell,重新登錄
docker開機(jī)需要手動(dòng)啟動(dòng),無法創(chuàng)建自啟動(dòng)
這個(gè)問題我還沒解決,我猜測(cè)是WSL缺少某些組件。我在這里記錄一下解決這個(gè)問題的步驟,以后參考。
這是我的wsl版本:
WSL 版本: 1.0.3.0
內(nèi)核版本: 5.15.79.1
WSLg 版本: 1.0.47
MSRDC 版本: 1.2.3575
Direct3D 版本: 1.606.4
DXCore 版本: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows版本: 10.0.19045.2604
添加自啟動(dòng)需要使用systemctl
,最新版的WSL默認(rèn)是不使用systemd的,可以通過下面的步驟配置使用
在WSL中打開終端,使用sudo vim /etc/wsl.conf
編輯(或使用其他熟悉的文本編輯命令)并添加如下內(nèi)容:
[boot]
systemd=true
必要時(shí)還要安裝systemctl
不過就算把docker.service加入開機(jī)自啟,也沒法真正做到讓docker自啟動(dòng)。我有時(shí)間要研究下systemmd的使用。
就目前來說,啟動(dòng) Ubuntu 后,需要輸入以下命令啟動(dòng) docker 服務(wù):文章來源:http://www.zghlxwxcb.cn/news/detail-477317.html
sudo service docker start
后續(xù)執(zhí)行docker命令,無需再調(diào)用sudo。文章來源地址http://www.zghlxwxcb.cn/news/detail-477317.html
到了這里,關(guān)于【W(wǎng)SL】Ubuntu 22.04 安裝配置docker的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!