wsl2中docker安裝完畢后無法正常啟動的解決方案
1、背景
在win10中安裝wsl2體驗(yàn)linux操作系統(tǒng),按照docker官網(wǎng)步驟安裝,安裝完畢后面提示
$ docker ps
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
$ docker info
Client: Docker Engine - Community
Version: 26.0.1
Context: default
Debug Mode: false
Plugins:
buildx: Docker Buildx (Docker Inc.)
Version: v0.13.1
Path: /usr/libexec/docker/cli-plugins/docker-buildx
compose: Docker Compose (Docker Inc.)
Version: v2.26.1
Path: /usr/libexec/docker/cli-plugins/docker-compose
Server:
ERROR: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
errors pretty printing info
2、目標(biāo)
啟動運(yùn)行docker
3、環(huán)境
| 項(xiàng)目 | 版本 |
|---|---|
| windows10 | 22H2 |
| wsl | 2 |
| ubuntu | 22.04 |
| docker | 226.0.1 |
4、原因
通過系統(tǒng)工具update-alternatives 可以配置和切換當(dāng)前系統(tǒng)中的iptables 環(huán)境做到多版本管理。
切換iptables版本解決WSL2中docker運(yùn)行異常的問題。
4、操作
4.1、查看配置
查看當(dāng)前配置信息
sudo update-alternatives --config iptables There are 2 choices for the alternative iptables (providing /usr/sbin/iptables). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/sbin/iptables-nft 20 auto mode 1 /usr/sbin/iptables-legacy 10 manual mode 2 /usr/sbin/iptables-nft 20 manual mode Press <enter> to keep the current choice[*], or type selection number: 1 update-alternatives: using /usr/sbin/iptables-legacy to provide /usr/sbin/iptables (iptables) in manual mode
4.2、 切換配置
輸入1 從iptables-nft路徑切換至iptables-legacy
4.3、啟動docker
$ sudo service docker start
4.4、驗(yàn)證docker
$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

總結(jié)
以上為個人經(jīng)驗(yàn),希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
docker desktop無法啟動的一種解決方法(附完整步驟)
這篇文章主要介紹了如何解決由于關(guān)閉虛擬化導(dǎo)致Docker Desktop無法啟動的問題,通過重新啟動虛擬化和WSL發(fā)行版解決了問題,并總結(jié)了其中的步驟和遇到的報(bào)錯,需要的朋友可以參考下2025-03-03
Dockerfile為鏡像添加SSH服務(wù)的實(shí)現(xiàn)步驟
利用 SSH 協(xié)議可以有效防止遠(yuǎn)程管理過程中的信息泄露問題,本文主要介紹了Dockerfile為鏡像添加SSH服務(wù)的實(shí)現(xiàn)步驟,具有一定的參考價值,感興趣的可以了解一下2024-03-03
無網(wǎng)絡(luò)docker鏡像遷移的實(shí)現(xiàn)
本文主要介紹了無網(wǎng)絡(luò)docker鏡像遷移的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2025-06-06
遷移變更Docker默認(rèn)數(shù)據(jù)存儲目錄的步驟詳解
Docker安裝的默認(rèn)數(shù)據(jù)目錄為/var/lib/docker,但是如果/目錄掛載的磁盤空間不夠,就需要遷移docker數(shù)據(jù)到其他目錄,接下來本就給大家介紹遷移變更Docker默認(rèn)數(shù)據(jù)存儲目錄的操作步驟,需要的朋友可以參考下2023-12-12

