I've tried to run Docker on WSL unsuccessfully. I've installed Docker on WSL following the steps given to install Docker on Ubuntu but when I execute docker ps I get the following error:
docker ps Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? Watching docker logs I found this:
level=warning msg="Running modprobe nf_nat failed with message: `modprobe: ERROR: ../libkmod/libkmod.c:586 kmod_search_moddep() could not open moddep file '/lib/modules/4.4.0-43-Microsoft/modules.dep.bin'\nmodprobe: WARNING: Module nf_nat not found in directory /lib/modules/4.4.0-43-Microsoft`, error: exit status 1" time="2017-12-28T12:07:23.227671600+01:00" level=warning msg="Running modprobe xt_conntrack failed with message: `modprobe: ERROR: ../libkmod/libkmod.c:586 kmod_search_moddep() could not open moddep file '/lib/modules/4.4.0-43-Microsoft/modules.dep.bin'\nmodprobe: WARNING: Module xt_conntrack not found in directory /lib/modules/4.4.0-43-Microsoft`, error: exit status 1" Error starting daemon: Error initializing network controller: error obtaining controller instance: failed to create NAT chain: iptables failed: iptables -t nat -N DOCKER: iptables v1.6.0: 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) Any idea how can I run Docker on WSL?
13 Answers
Finally, I could run Docker on WSL in an easy way: You need first to install and run Docker Engine on Windows and then just create a symbolic link on Ubuntu bash pointing to the Windows executable:
sudo ln -s /mnt/c/Program\ Files/Docker/Docker/resources/bin/docker.exe /usr/bin/docker This link works because from version Windows 10 Creators Update it's possible to run Windows executables from Bash. If your Windows version is previous to Windows 10 Creators Update you can try the solution explained in this blog
3failed to create NAT chain: iptables failed
Try running dockerd service with --iptables=false (consider adding -D for debug).
4
--iptablesEnable addition of iptables rules (default true)
In my case the issue was related to the version of wsl. I changed it to version 2 and reinstalled Ubuntu-20.04 and docker and everything worked fine.
wsl --set-default-version 2 3Good news! The real linux Docker daemon runs great on build 17134 thus there won't need for the Windows Docker or Hyper-V anymore. I 'm testing the build on Release Preview ring and I just compiled docker sources inside a linux container inside WSL without problem!
Just wait for the next Windows 10 feature release which will come for everyone in the next weeks!
3Trying to run the Linux dockerd daemon with WSL is unlikely to work, Docker for Linux needs a Linux kernel to run, while WSL is the Windows kernel that implements Linux syscalls to allow you to run Linux programs.
Instead, you should install docker for windows which supports Linux containers using an embedded Linux VM (Hyper-V or VirtualBox depending on your version). Once you have installed the Windows version of docker, you'll have the docker client that you can access from various command lines, including cmd and bash.
The given answer is out of date. Follow the instructions from the same blog, linked to in the that post: Running Docker containers on Bash on Windows. The solution is still very simple.
- Install docker on Windows
- Add the following lines into your .bashrc, .zshrc, .whateverrc on your WSL
export PATH="/mnt/c/Program\ Files/Docker/Docker/resources/bin:$PATH" alias docker=docker.exe alias docker-compose=docker-compose.exe That's it. It works.
At this very moment you just cannot run dockerd and the actual docker runtime inside WSL. Although by no means, it means that it won't be possible in the future.
Still you may use the docker client from WSL to control your Windows² docker daemon and its containers.
In WSL, just do an export DOCKER_HOST='tcp://localhost:2375'. Additionally allow TCP access in your Windows² Docker settings. Now you may execute docker ps and see the containers that are powered by dockerd on Windows².
If you Cannot connect to the Docker daemon at tcp://localhost:2375. Is the docker daemon running?, it means that you did not enabled TCP access in your Docker settings on Windows.
² actually Windows does not support Docker at all. A Hyper-V "Moby" Linux instance enables Docker on Windows.
- Install
"Docker for windows". "Docker for windows" > settings > generalEnableexpose on tcp//*** without TLS.- Run following snippet on sybsystem to install docker cli
DOCKERVERSION=18.03.1-ce curl -fsSLO \ && tar xzvf docker-${DOCKERVERSION}.tgz --strip 1 -C /usr/local/bin docker/docker \ && rm docker-${DOCKERVERSION}.tgz export DOCKER_HOST='tcp://localhost:2375'on sybsystem.
For Window 10 - Build 1909
This worked for me. Run these commands inside WLS Ubuntu.
$ sudo ln -s /mnt/c/Program\ Files/Docker/Docker/resources/bin/docker.exe /usr/bin/docker $ alias docker='docker.exe' $ alias docker-compose=docker-compose.exe Windows doesn't let WSL to use TCP for Docker, so you need to link docker file to the docker.exe in windows.
0On newer win10 builds, docker-desktop seems to be mounted into the wsl linux client already since it (the linux distro) can access the underlying file system with ease.
So in order to access docker desktop it is as easy as:
$ docker.exe -h or
$ docker-compose.exe -h For this you can then just add internal alias as following:
$ alias docker='docker.exe' $ alias docker-compose=docker-compose.exe It seems that whether Docker functions properly on WSL may depend on a number of factors, so the right answer on some systems may not be right for all. For me, I couldn't get it to run properly until I installed WSL2, which requires a Windows 10 build that's currently only available by signing up for the Windows Insider Program (as of May 2020). After scouring the web and failing with multiple approaches, I finally came across this article, which had the right answers for me.
The two caveats to the article for me were that 1. I had to enable "virtualization" (for running virtual machines) in my bios, and 2. The final command for installing docker-compose didn't seem to work, so I followed this.
*Finally, I should note that Docker Desktop will not run on Windows 10 Home edition, so WSL2 was the only option on my system.
dockerd --debug --iptables=false & That will start docker service, also, you can run without --debug
Try this command
sudo docker pull Change the version of your mssql server before execute.