Home:ALL Converter>Run Docker on Ubuntu on Windows Subsystem for Linux

Run Docker on Ubuntu on Windows Subsystem for Linux

Ask Time:2017-12-28T21:48:56         Author:Andrés Cuadros

Json Formatter

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?

Author:Andrés Cuadros,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/48008675/run-docker-on-ubuntu-on-windows-subsystem-for-linux
kenorb :

\nfailed to create NAT chain: iptables failed\n\nTry running dockerd service with --iptables=false (consider adding -D for debug).\n\n--iptables Enable addition of iptables rules (default true)\n",
2020-10-08T11:36:18
onoma :

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!\n\nJust wait for the next Windows 10 feature release which will come for everyone in the next weeks!",
2018-04-24T22:35:13
Alex A. :

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.\nwsl --set-default-version 2\n",
2022-01-25T16:06:25
BMitch :

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.\n\nInstead, 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.",
2017-12-28T13:56:44
Mark Chassy :

The given answer is out of date.\nFollow 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.\n\n\nInstall docker on Windows\nAdd the following lines into your .bashrc, .zshrc, .whateverrc on your WSL\n\n\nexport PATH=\"/mnt/c/Program\\ Files/Docker/Docker/resources/bin:$PATH\"\nalias docker=docker.exe\nalias docker-compose=docker-compose.exe\n\n\nThat's it. It works.",
2019-11-29T14:20:28
Alex :

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.\n\nStill you may use the docker client from WSL to control your Windows² docker daemon and its containers.\n\nIn 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².\n\nIf 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.\n\n² actually Windows does not support Docker at all. A Hyper-V \"Moby\" Linux instance enables Docker on Windows.",
2018-07-12T13:46:41
Janitha Madushan :

\nInstall \"Docker for windows\".\n\"Docker for windows\" > settings > general Enable expose on tcp//*** without TLS.\nRun following snippet on sybsystem to install docker cli\n\n\n\n\nDOCKERVERSION=18.03.1-ce\ncurl -fsSLO https://download.docker.com/linux/static/stable/x86_64/docker-${DOCKERVERSION}.tgz \\\n&& tar xzvf docker-${DOCKERVERSION}.tgz --strip 1 -C /usr/local/bin docker/docker \\\n&& rm docker-${DOCKERVERSION}.tgz\n\n\n\nexport DOCKER_HOST='tcp://localhost:2375'on sybsystem.\n",
2018-09-18T08:00:06
msahin :

For Window 10 - Build 1909\n\nThis worked for me. Run these commands inside WLS Ubuntu.\n\n$ sudo ln -s /mnt/c/Program\\ Files/Docker/Docker/resources/bin/docker.exe /usr/bin/docker\n$ alias docker='docker.exe'\n$ alias docker-compose=docker-compose.exe\n\n\nWindows doesn't let WSL to use TCP for Docker, so you need to link docker file to the docker.exe in windows.",
2020-02-15T19:20:10
Ark B :

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.\n\nThe 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.\n\n*Finally, I should note that Docker Desktop will not run on Windows 10 Home edition, so WSL2 was the only option on my system.",
2020-05-11T07:47:32
Andrés Cuadros :

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:\n\nsudo ln -s /mnt/c/Program\\ Files/Docker/Docker/resources/bin/docker.exe /usr/bin/docker\n\n\nThis 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",
2017-12-28T13:48:56
mao fw :

dockerd --debug --iptables=false &\n\nThat will start docker service, also, you can run without --debug",
2022-11-12T01:32:52
yy