for-linux
for-linux copied to clipboard
Failure to install and run Docker in WSL Ubuntu 22.04 (works in 20.04): "Cannot connect to the Docker daemon"
- [x] This is a bug report
- [ ] This is a feature request
- [x] I searched existing issues before opening this one
Steps to reproduce the behavior
OS: Windows 10 21H2
Enabled features: Virtual Machine Platform, Windows Subsystem for Linux
Steps: Install a WSL Ubuntu 22.04 distribution and run it. Set any username/password during installation password. Perform all steps from official Docker installation guide (https://docs.docker.com/engine/install/ubuntu/):
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg lsb-release
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
Start service: sudo service docker start
.
Verify installation: sudo docker run hello-world
.
Expected behavior
sudo docker run hello-world
starts a sample container.
Actual behavior
sudo docker run hello-world
fails with a message docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
.
!!!!!! NOTE: the same steps works ok with Ubuntu 20.04 !!!!!!
Output of docker version
:
Docker version 20.10.17, build 100c701
Output of docker info
:
Client:
Context: default
Debug Mode: false
Plugins:
app: Docker App (Docker Inc., v0.9.1-beta3)
buildx: Docker Buildx (Docker Inc., v0.8.2-docker)
compose: Docker Compose (Docker Inc., v2.6.0)
scan: Docker Scan (Docker Inc., v0.17.0)
Server:
ERROR: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/info": dial unix /var/run/docker.sock: connect: permission denied
errors pretty printing info
sudo journalctl -fu docker.service
gives
No journal files were found.
Facing the same issue. Does anybody has a solution for this please?
Are you fully updated?
sudo apt update && sudo apt full-upgrade -y
If you are then maybe you could try using one of the 2 other ways :
-
curl -fsSL https://get.docker.com | sh
-
sudo apt update && sudo apt install docker.io -y
You could also try manually download the repo packages through wget on https://download.docker.com/linux/ubuntu/dists/jammy/pool/stable/amd64/ to get the packages for 22.04
Fully updated, services don't start at all. 22.04 is completely boinked.
sudo service ssh start
* Starting OpenBSD Secure Shell server sshd
sshd: no hostkeys available -- exiting.
It seems that you are using WSL version 1.
check the WSL version in Powershell
wsl -l -v
If you have version 1, WSL 1 did not support running Docker within the Ubuntu subsystem on its own. The WSL 1 required to use Windows Desktop Docker app to be installed and use windows binaries to run Docker within WSL. This is great if you need to keep the 2 docker services in sync.
If you want to run Docker within WSL without having the windows Docker client, you have to update it to WSL2. Uninstall the current Ubuntu installation from Settings -> Apps -> Ubuntu. Then switch the WSL version 2, then install the Ubuntu again.
As a workaround in dev environment, I installed Docker using the convenience script that installed the latest stable release of Docker (Docker version 20.10.17, build 100c701
) on my Ubuntu 20.04.4 LTS (Focal Fossa) machine.
@Adverte No, it's WSL 2.
In Ubuntu 22.04, it might have an issue with the iptables version. When checking the status, it might still show up not running. Hence, please make sure to switch the iptables to legacy.
To switch to iptables-legacy, run the below command to change the default iptables version.
sudo update-alternatives --config iptables
Then re-start docker service
sudo service docker start
And check docker status again with
sudo service docker status
If this can solve your problem, please close the issue.
The above solution worked for me, without needing Docker Desktop.
I have no idea how modifying the iptables will affect everything else though.
Does this mean that we shouldn't bother with 22.04 for WSL in general and just stick with 20.04?
@YoshikoJanai imo, you can do anything you want, unless you want to have a specific feature that the lower version doesn't satisfy your desire.
@40rn05lyv did it work from your side?
In Ubuntu 22.04, it might have an issue with the iptables version. When checking the status, it might still show up not running. Hence, please make sure to switch the iptables to legacy.
To switch to iptables-legacy, run the below command to change the default iptables version.
sudo update-alternatives --config iptables
Then re-start docker service
sudo service docker start
And check docker status again with
sudo service docker status
If this can solve your problem, please close the issue.
I had this issue with Linux Mint 21 upgrade; setting iptables to legacy fixed docker not starting.
similar issues for me too
tried some workarounds
and found that somehow if you keep sudo dockerd
running in background it seems to be working normally
and then if you kill background task then whole thing turns back off
A sample log file/demonstration
root@PRAKASH:~# nohup sudo dockerd & [1] 2720 nohup: ignoring input and appending output to 'nohup.out'
root@PRAKASH:~# sudo docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 2db29710123e: Pull complete Digest: sha256:7d246653d0511db2a6b2e0436cfd0e52ac8c066000264b3ce63331ac66dca625 Status: Downloaded newer image for hello-world:latest
Hello from Docker! This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
- The Docker client contacted the Docker daemon.
- The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64)
- The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading.
- 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/
root@PRAKASH:# ps -a PID TTY TIME CMD 2720 pts/0 00:00:00 sudo 2722 pts/1 00:00:01 dockerd 2967 pts/0 00:00:00 ps root@PRAKASH:# kill 2722 root@PRAKASH:# ps -a PID TTY TIME CMD 2968 pts/0 00:00:00 ps [1]+ Done nohup sudo dockerd root@PRAKASH:# sudo docker run hello-world docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?. See 'docker run --help'.
In Ubuntu 22.04, it might have an issue with the iptables version. When checking the status, it might still show up not running. Hence, please make sure to switch the iptables to legacy.
To switch to iptables-legacy, run the below command to change the default iptables version.
sudo update-alternatives --config iptables
Then re-start docker service
sudo service docker start
And check docker status again with
sudo service docker status
If this can solve your problem, please close the issue.
I had the same issue upon upgrading wsl to jammy 22.04. I changed iptables to legacy via update-alternatives like you suggested, and the docker service seems to be running now. Thank you.
Was facing the same issue and solved with @ThaiLe011094 solution! Thank you!
In Ubuntu 22.04, it might have an issue with the iptables version. When checking the status, it might still show up not running. Hence, please make sure to switch the iptables to legacy.
To switch to iptables-legacy, run the below command to change the default iptables version.
sudo update-alternatives --config iptables
Then re-start docker service
sudo service docker start
And check docker status again with
sudo service docker status
If this can solve your problem, please close the issue.
thanks it help, after upgrade to 22.04
+1 on the firewall issue! thanks @ThaiLe011094
In Ubuntu 22.04, it might have an issue with the iptables version. When checking the status, it might still show up not running. Hence, please make sure to switch the iptables to legacy.
To switch to iptables-legacy, run the below command to change the default iptables version.
sudo update-alternatives --config iptables
Then re-start docker service
sudo service docker start
And check docker status again with
sudo service docker status
If this can solve your problem, please close the issue.
Thank you.
I had the same error; upgrading the Linux distro to WSL version 2 and integrating it to the Docker Windows fixed it.
https://docs.docker.com/desktop/windows/wsl/#enabling-docker-support-in-wsl-2-distros
This was able to get docker to start but broke the internet access on the WSL.
In Ubuntu 22.04, it might have an issue with the iptables version. When checking the status, it might still show up not running. Hence, please make sure to switch the iptables to legacy.
To switch to iptables-legacy, run the below command to change the default iptables version.
sudo update-alternatives --config iptables
Then re-start docker service
sudo service docker start
And check docker status again with
sudo service docker status
If this can solve your problem, please close the issue.
thanks
I was having same problem with Windows 11 Pro. Problem resolved after following @ThaiLe011094 's method.
In Ubuntu 22.04, it might have an issue with the iptables version. When checking the status, it might still show up not running. Hence, please make sure to switch the iptables to legacy.
To switch to iptables-legacy, run the below command to change the default iptables version.
sudo update-alternatives --config iptables
Then re-start docker service
sudo service docker start
And check docker status again with
sudo service docker status
If this can solve your problem, please close the issue.
Below is my machine configuration. Hope that helps.
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.2 LTS
Release: 22.04
Codename: jammy
$ sudo docker version
Client: Docker Engine - Community
Version: 23.0.1
API version: 1.42
Go version: go1.19.5
Git commit: a5ee5b1
Built: Thu Feb 9 19:47:01 2023
OS/Arch: linux/amd64
Context: default
Server: Docker Engine - Community
Engine:
Version: 23.0.1
API version: 1.42 (minimum version 1.12)
Go version: go1.19.5
Git commit: bc3805a
Built: Thu Feb 9 19:47:01 2023
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.19
GitCommit: 1e1ea6e986c6c86565bc33d52e34b81b3e2bc71f
runc:
Version: 1.1.4
GitCommit: v1.1.4-0-g5fd4c4d
docker-init:
Version: 0.19.0
GitCommit: de40ad0
@40rn05lyv did it work from your side?
In Ubuntu 22.04, it might have an issue with the iptables version. When checking the status, it might still show up not running. Hence, please make sure to switch the iptables to legacy. To switch to iptables-legacy, run the below command to change the default iptables version.
sudo update-alternatives --config iptables
Then re-start docker servicesudo service docker start
And check docker status again withsudo service docker status
If this can solve your problem, please close the issue.
After few hours of digging, your solution worked. Thank you
Are you fully updated?
sudo apt update && sudo apt full-upgrade -y
If you are then maybe you could try using one of the 2 other ways :
curl -fsSL https://get.docker.com | sh
sudo apt update && sudo apt install docker.io -y
You could also try manually download the repo packages through wget on https://download.docker.com/linux/ubuntu/dists/jammy/pool/stable/amd64/ to get the packages for 22.04
Thanks! This worked for me! => sudo apt update && sudo apt full-upgrade -y
I have a similar problem but its a little bit different, i have installed docker desktop with wsl2 on my ubuntu 22.04. It worked pretty well the installation but when i try to run the hello-world container it keeps sending me this message:
docker: request returned Internal Server Error for API route and version http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/create, check if the server supports the requested API version.
I wonder if there's anything i have done wrong...
EDIT: I have tried to switch the iptables to legacy but it didnt work.
我有一个类似的问题,但它有点不同,我已经在我的 ubuntu 2.22 上安装了带有 wsl04 的 docker 桌面。它的安装效果很好,但是当我尝试运行hello-world容器时,它一直向我发送以下消息:
docker: request returned Internal Server Error for API route and version http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/create, check if the server supports the requested API version.
我想知道我是否做错了什么...
编辑:我试图将iptables切换到旧版,但它不起作用。
same problems
after install it's work, but after reboot Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
I have the same problem (Windows 11 + WSL 2 → Ubuntu 22.04.3 LTS).
I need to take some actions every morning (when I turn on my pc):
sudo dockerd --debug
That can't start and show me the message:
failed to start daemon, ensure docker is not running or delete /var/run/docker.pid: process with PID 25 is still running
sudo rm -rf /var/run/docker.pid
sudo kill 25
sudo dockerd --debug
That starts normally. So I cancel it (CTRL+C)
sudo service docker start
That starts normallly.
After this, my day starts.
I have the same issue with WSL2 Ubuntu-22.04 on windows 11
failed to start daemon: Error initializing network controller: error obtaining controller instance: unable to add return rule in DOCKER-ISOLATION-STAGE-1 chain: (iptables failed: iptables --wait -A DOCKER-ISOLATION-STAGE-1 -j RETURN: iptables v1.8.7 (nf_tables): RULE_APPEND failed (No such file or directory): rule in chain DOCKER-ISOLATION-STAGE-1 (exit status 4))
switching iptables to legacy version solved the issue ( sudo update-alternatives --config iptables
)
I get this error:
DEBU[2023-09-07T23:48:42.589375188-05:00] Cleaning up old mountid : done.
failed to start daemon: Error initializing network controller: error obtaining controller instance: failed to create NAT chain DOCKER: iptables failed: iptables -t nat -N DOCKER: modprobe: FATAL: Module ip_tables not found in directory /lib/modules/6.5.0-joeln2
iptables v1.8.7 (legacy): can't initialize iptables table `nat': Table does not exist (do you need to insmod?)
Perhaps iptables or your kernel needs to be upgraded.
(exit status 3)
I can tell right away this is due to my customized Kernel. Docker appears to need modules within the Kernel that most things don't need. I know that I stripped down IPtables. It would be nice to find a Docker list of Kernel module dependencies.
So for some of you, maybe try one of the default Ubuntu Kernels? I'll mess with this more this weekend, hopefully.