Cannot connect to the Docker daemon on bash on Ubuntu windows
Found the solution on this post: https://blog.jayway.com/2017/04/19/running-docker-on-bash-on-windows/
Running docker against an engine on a different machine is actually quite easy, as Docker can expose a TCP endpoint which the CLI can attach to.
This TCP endpoint is turned off by default; to activate it, right-click the Docker icon in your taskbar and choose Settings, and tick the box next to “Expose daemon on tcp://localhost:2375 without TLS”.
With that done, all we need to do is instruct the CLI under Bash to connect to the engine running under Windows instead of to the non-existing engine running under Bash, like this:
$ docker -H tcp://0.0.0.0:2375 images
There are two ways to make this permanent – either add an alias for the above command or export an environment variable which instructs Docker where to find the host engine (NOTE: make sure to use single apostrophe's below):
$ echo "export DOCKER_HOST='tcp://0.0.0.0:2375'" >> ~/.bashrc
$ source ~/.bashrc
Now, running docker commands from Bash works just like they’re supposed to.
$ docker run hello-world
Successful response:
Hello from Docker!This message shows that your installation appears to be working correctly.
The Docker client and server can now be installed and run purely in WSL without Docker Desktop for Windows if you are running Windows 10 version 1803 or greater. I have it working on the following WSL:
OS: Ubuntu 18.04 bionic [Ubuntu on Windows 10]
Kernel: x86_64 Linux 4.4.0-17763-Microsoft
Simply follow the same instructions to install on Ubuntu but make sure to choose a specific version to install. Presently, version 18.06.1~ce~3-0~ubuntu works fine but later versions up to 5:18.09.6~3-0~ubuntu-bionic have an issue with starting up a container. The following command will install the latest working version:
apt-get install docker-ce=18.06.1~ce~3-0~ubuntu
To get the Docker server running in WSL after installation, close all open terminals and start a new Ubuntu terminal as administrator (i.e., right click the Ubuntu shortcut and click 'Run as administrator'). Finally, run the following commands:
sudo cgroupfs-mount
sudo service docker start
sudo service docker start
will have to be run each time Windows is rebooted. However, if you wish to avoid that, you can automate it using the Task Scheduler and a shell script by following the steps listed here.
Test that everything is working using:
docker run hello-world
Reference: https://medium.com/faun/docker-running-seamlessly-in-windows-subsystem-linux-6ef8412377aa
for me this worked for WSL for windows:
- 1> go to: Turn Windows features on or off
- 2> deselect "Hyper-V", restart,
- 3> go to "Turn Windows features on or off" again,
- 4> select "Hyper-V" again
- and restart a last time. Afterwards docker was reachable again.
assuming you have installed docker desktop for windows and Settings->General->Expose daemon on tcp://localhost:2375 without TLS is ticked
Note: if you are using the Ubuntu from WSL (Windows Subsystem for Linux), do understand that the docker client is working, not the docker server (daemon).
See Microsoft/WSL issue 2114 and this thread.
For the server, you would still need to use only Docker for Windows and its Hyper-V VM.
Then, Microsoft/WSL issue 2102 adds:
I was able to make TLS work from inside WSL by changing
DOCKER_CERT_PATH
environment variable (which I got from runningeval $(docker-machine.exe env --shell bash)
) from "C:\C:\Users\mmarchini\.docker\machine\machines\default
" to "/mnt/c/Users/mmarchini/.docker/machine/machines/default/
" .
At least docker build seems to be working now, I'll try usingdocker-compose
later.
See this script (from Matheus Marchini) to launch a docker-machine bash with the right setting:
#!/usr/bin/env python3
from subprocess import run, PIPE
completed_process = run(["docker-machine.exe", "env", "--shell", "bash"], stdout=PIPE)
docker_env = completed_process.stdout.decode("ascii")
for line in docker_env.split("\n"):
if "DOCKER_CERT_PATH" in line:
env_var, path, _ = line.split('"')
path = path.replace("\\", "/")
drive, path = path.split(":", 1)
path = "/mnt/{}{}".format(drive.lower(), path)
line = '{}"{}"'.format(env_var, path)
print(line)