'Run Docker on Ubuntu on Windows Subsystem for Linux

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?



Solution 1:[1]

Good 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!

Solution 2:[2]

failed to create NAT chain: iptables failed

Try running dockerd service with --iptables=false (consider adding -D for debug).

--iptables Enable addition of iptables rules (default true)

Solution 3:[3]

Trying 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.

Solution 4:[4]

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.

Solution 5:[5]

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

Solution 6:[6]

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.

Solution 7:[7]

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.

Solution 8:[8]

  1. Install "Docker for windows".
  2. "Docker for windows" > settings > general Enable expose on tcp//*** without TLS.
  3. Run following snippet on sybsystem to install docker cli
DOCKERVERSION=18.03.1-ce
curl -fsSLO https://download.docker.com/linux/static/stable/x86_64/docker-${DOCKERVERSION}.tgz \
&& tar xzvf docker-${DOCKERVERSION}.tgz --strip 1 -C /usr/local/bin docker/docker \
&& rm docker-${DOCKERVERSION}.tgz
  1. export DOCKER_HOST='tcp://localhost:2375'on sybsystem.

Solution 9:[9]

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.

Solution 10:[10]

Try this command

sudo docker pull mcr.microsoft.com/mssql/server:2019-latest

Change the version of your mssql server before execute.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 onoma
Solution 2 kenorb
Solution 3 BMitch
Solution 4 Mark Chassy
Solution 5 Alex A.
Solution 6 Alex
Solution 7
Solution 8
Solution 9 Ark B
Solution 10 test localhost