127

My understanding was that the primary limitation of running docker on other OSs was the Linux Network containers that made it possible. (Certainly for Macs).

Recently Microsoft announced a beta of a Ubuntu linux user mode running natively on Windows 10. This can run binaries compiled in ELF format on Windows (unlike cygwin which requires a compilation.)

My question is: Can you run Docker natively on the new Windows 10 (Ubuntu) bash userspace?

Hawkeye
  • 2,669
  • 9
  • 30
  • 34
  • 4
    It's not "just" a `bash` userspace. It's a real, fairly complete Linux userspace, but without X Windows i.e. text only. Saying "bash" communicates the text-only limitation quite well.. – MSalters Apr 04 '16 at 14:16
  • Did I miss something? Did this actually get distributed? At the moment I only know of it as vaporware. – Michael Hampton Apr 04 '16 at 17:43
  • 2
    I think it won't be clear until they release this (AFAIK it's not even available to windows insiders as yet) however it's worth noting that Microsoft and Docker are working on bringing Docker to Windows natively, to be released alongside Windows server 2016 – Rory McCune Apr 04 '16 at 20:18
  • 1
    @RоryMcCune: Interesting. However, according to [this Docker blog entry](https://blog.docker.com/2015/08/tp-docker-engine-windows-server-2016/) from August 2015, this will be a port that allows Docker to run _Windows_ images on Windows, not Linux images on Windows. – sleske Apr 05 '16 at 07:21
  • 2
    indeed that's the purpose of the Windows native docker. The nature of containerisation is that you can't run systems with other kernels, without adding in some virtualisation or (possibly) this new subsystem that Microsoft are developing – Rory McCune Apr 05 '16 at 07:25
  • For a GNU system to run on a Windows kernel is certainly possible. It would be a LOT of work for a very lateral shift in quality. I would be surprised if it happened, or if people adopted it. – Spooler Apr 23 '17 at 03:42
  • Is it possible to run windows docker image on ubuntu aws instance ? or is there some alternative ? ......root@ip-172-31-22-20:~/docker/windows# docker pull microsoft/nanoserver Using default tag: latest latest: Pulling from microsoft/nanoserver bce2fbc256ea: Pulling fs layer 4806a44e00a0: Pulling fs layer image operating system "windows" cannot be used on this platform root@ip-172-31-22-20:~/docker/windows# – Ashish Karpe Dec 18 '17 at 10:01
  • Related: [docker error: /var/run/docker.sock: no such file or directory](https://stackoverflow.com/q/25372781/55075). – kenorb Aug 01 '18 at 23:00

10 Answers10

104

You can use Docker Desktop for Windows as the engine and Docker for Linux as the client in WSL on Ubuntu / Debian on Windows. Connect them via TCP.

Install Docker Desktop for Windows: https://hub.docker.com/editions/community/docker-ce-desktop-windows If you want to use Windows Containers instead of Linux Containers both type containers can be managed by the Linux docker client in the bash userspace.

Since version 17.03.1-ce-win12 (12058) you must check Expose daemon on tcp://localhost:2375 without TLS to allow the Linux Docker client to continue communicating with the Windows Docker daemon by TCP

Follow these steps:

cd
wget https://download.docker.com/linux/static/stable/`uname -m`/docker-19.03.1.tgz
tar -xzvf docker-*.tgz
cd docker
./docker -H tcp://0.0.0.0:2375 ps

or

env DOCKER_HOST=tcp://0.0.0.0:2375 ./docker ps

To make it permanent:

mkdir ~/bin
mv ~/docker/docker ~/bin

Add the corresponding variables to .bashrc

export DOCKER_HOST=tcp://0.0.0.0:2375
export PATH=$PATH:~/bin

Of course, you can install docker-compose

sudo -i
curl -L https://github.com/docker/compose/releases/download/1.24.1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

Or using python pip

sudo apt-get install python-pip bash-completion
sudo pip install docker-compose

And Bash completion. The best part:

sudo -i
apt-get install bash-completion
curl -L https://raw.githubusercontent.com/docker/docker-ce/master/components/cli/contrib/completion/bash/docker > /etc/bash_completion.d/docker
curl -L https://raw.githubusercontent.com/docker/compose/$(docker-compose version --short)/contrib/completion/bash/docker-compose > /etc/bash_completion.d/docker-compose

I've tested it using the 2.1.0.1 (37199) version of Docker Desktop using Hyper-V:

$ docker version
Client: Docker Engine - Community
 Version:           19.03.1
 API version:       1.40
 Go version:        go1.12.5
 Git commit:        74b1e89e8a
 Built:             Thu Jul 25 21:17:37 2019
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.1
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.5
  Git commit:       74b1e89
  Built:            Thu Jul 25 21:17:52 2019
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          v1.2.6
  GitCommit:        894b81a4b802e4eb2a91d1ce216b8817763c29fb
 runc:
  Version:          1.0.0-rc8
  GitCommit:        425e105d5a03fabd737a126ad93d62a9eeede87f
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683
Look both client and server say **OS/Arch: linux/amd64**

Volumes

Take care when adding volumes. The path C:\dir will be visible as /mnt/c/dir on WSL and as /c/dir/ by docker engine. You can overcome it permanently:

sudo bash -c "echo -e '[automount] \nroot = /'>/etc/wsl.conf"

You must exit and reload WSL after making the change to wsl.conf so that WSL reads in your changes on launch.

UPDATE

from: What’s new for the Command Line in Windows 10 version 1803

Unix Sockets Unix Sockets weren't supported on Windows, and now they are! You can also communicate over Unix sockets between Windows and WSL. One of the great things about this is it enables WSL to run the Linux Docker Client to interact with the Docker Daemon running on Windows.

UPDATE

This script and the use of Unix Sockets was included in Pengwin's pengwin-setup.

Regards

Carlos Rafael Ramirez
  • 1,201
  • 2
  • 9
  • 8
  • I think this answer has missed the point of the question and this line gives it away _I've tested it using the 1.12 version of Docker for Windows using Hyper-V_. @crramirez is running the virtualised version of docker for Windows as a full VM. This question is about the _Windows System for Linux (WSL)_ which is a Linux emulation layer. Unless it is implied he installed Ubuntu Bash on Windows, but he never mentions it specifically. – Joel Pearson Aug 17 '16 at 02:04
  • 3
    Hello @joel-pearson, docker have two parts: the engine and the client. The engine run in windows using Docker Toolbox (VirtualBox based) or Docker for Windows (Hyper-V based) both officially supported by docker team. Docker engine doesn't run in bash user space yet. Docker client in windows can be run in cmd, powershell or cygwin. What this answer say is the way to run the docker client in bash userspace. Why? Personally I prefer bash, the completion works. I agree that the question is regarding docker engine, but I found it when I was looking for the client, and many people do the same. – Carlos Rafael Ramirez Aug 17 '16 at 13:27
  • 1
    I just tested it and it works for me on 1.12 :) Super excited to now be able to do some serious development on windows. – Zach Russell Sep 28 '16 at 22:17
  • 2
    Tried your instructions in Bash on Ubuntu on Windows, got "Cannot connect to the Docker daemon. Is the docker daemon running on this host?". Are you missing some steps? – mpen Oct 09 '16 at 20:17
  • 1
    @mpen Before executing my steps, first be sure you have Docker for Windows installed and running – Carlos Rafael Ramirez Oct 09 '16 at 23:46
  • I am seeing the same problem as @mpen. I have docker installed and running when I try from powershell or command prompt. I tried using admin command/powershell terminals as well. – Kiran Jan 06 '17 at 19:31
  • Check if the docker notification icon is moving or is static. If it is moving docker is not ready yet for connection. If it is static well it is another problem. – Carlos Rafael Ramirez Jan 06 '17 at 19:44
  • Thanks Carlos, I followed the instructions here: https://docs.microsoft.com/en-us/virtualization/windowscontainers/quick-start/quick-start-windows-10 There is no icon installed – Kiran Jan 06 '17 at 22:15
  • I recommend you to install Docker for Windows Beta. It includes Windows Containers as well and it takes care of everything is needed to have Docker running. The stable version doesn't include yet Windows containers – Carlos Rafael Ramirez Jan 06 '17 at 22:21
  • https://download.docker.com/win/beta/InstallDocker.msi – Carlos Rafael Ramirez Jan 06 '17 at 22:31
  • 5
    As of February 2017, this is still the only way. – Dave Feb 17 '17 at 19:35
  • I installed the [latest CE edition](https://docs.docker.com/engine/installation/linux/ubuntu/), as well as running the docker-for-windows, and only had to `export DOCKER_HOST=tcp://0.0.0.0:2375`. It seems it is working but on build I get "sending build context to docker daemon"! – dashesy Mar 15 '17 at 20:01
  • I have had problems with docker build and docker cp in this mode. So I recommed using the windows client for these two cases. – Carlos Rafael Ramirez Mar 16 '17 at 03:07
  • The main problem with using Docker for Windows is that inotify isn't working. This means if you are using file watchers such as fresh then they won't work. – Jón Trausti Arason Apr 25 '17 at 12:10
  • When I have mounted files with docker-compose in this setup, I get the error "Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type". Did anyone have that as well and found a solution? – Rüdiger Schulz Sep 11 '17 at 00:44
  • 3
    After June 2017, you can [run the *docker for windows* executables from the bash shell](https://blog.jayway.com/2017/04/19/running-docker-on-bash-on-windows/). Instead of installing the docker client you can use the `docker.exe` directly to query/interact the docker subsystem. However, note that the docker for windows will use the windows variables and configurations. – Jaime Sep 16 '17 at 18:09
51

As of right now (April 2016) the answer is:

We do not know yet (but probably not).

The facts

  • Windows 10 can now run a variety of Linux programs (among them the Bash shell and various text utilities). These are not ports (i.e. recompiled versions, like for example in Cygwin), they are the same ELF binaries that run on a typical Linux system. In this case, they were taken from Ubuntu.
  • To make this possible, Windows 10 was modified to accept Linux System calls (syscalls), and to be able to load and run ELF binaries (comment by Scott Hanselman). This means unmodified Linux executables can be run, they will load their unmodified shared libraries as required, and Windows will run them as Windows processes.
  • Whenever such a Linux program wants to interact with the kernel, it issues a system call (or lets a library do it). This is (presumably) the only difference to running on Linux: When running on Linux, the Linux kernel handles theses calls; on Windows 10, the Windows 10 kernel does it instead.

The speculation

So the question is whether the syscalls that Docker needs (for chroot and namespaces, among other things) were implemented or not. The answer is to that is likely "no". Docker requires fairly sophisticated (and Linux-specific) functionality for process and resource management, and process isolation. While it is probably possible to replicate all this on Windows, it would be a lot of work, and since the goal of this Windows feature seems to be running Linux userspace programs, it seems unlikely they did all the work (and kept it secret).

However, there is no definitive information either way,as far as I can tell.

Existing Docker ports

Of course, if Microsoft decides they want Docker support in Windows 10, they will probably able to offer it. There is some precedent for porting Docker to a different kernel:

  • There is a Docker port for FreeBSD. It is labeled "experimental", but in seems to work in principle. It can use unmodified Docker containers from the Docker repository, meaning it actually provides a Linux-like host environment for the images.
  • There is a project underway for porting Docker to Windows (specifically, Windows Server 2016) - see this Docker blog entry from August 2015. However, unlike the FreBSD port above, this will be a port that allows Docker to run Windows images on Windows, not Linux images on Windows. Thanks to Rоry McCune for pointing this out.
sleske
  • 9,851
  • 4
  • 33
  • 44
  • 1
    Update: There's an article on the topic on an MSDN blog now: [Windows Subsystem for Linux Overview](https://blogs.msdn.microsoft.com/wsl/2016/04/22/windows-subsystem-for-linux-overview/). – sleske Apr 28 '16 at 08:43
  • As of today it's possible with Hyper-V: https://tutorials.ubuntu.com/tutorial/tutorial-windows-ubuntu-hyperv-containers?backURL=/#0 – Nick Sweeting Oct 26 '17 at 03:57
  • I downvoted simply because the higher voted answer is more useful then speculation of what may be, it covers what is. – James Jan 26 '18 at 19:32
13

No, this is not possible.

Docker needs multiple things in order to run containers:

  • chroot
  • Namespaces for:
    • PID
    • Users
    • Network
    • Mounts
    • UTS
    • IPC

These are all kernel features that are implemented in Linux. Unfortunately, most of them do not have a similar feature in Windows to use as a replacement (nor in the Linux Subsystem that Microsoft implemented in the Windows kernel). All these need to be provided by the OS.

Florin Asăvoaie
  • 6,932
  • 22
  • 35
  • 4
    Actually, Windows does have namespaces for Users, Mounts and IPC. User namespaces are required for Active Directory, mount namespaces and IPC namespaces are required for multi-user operation. Fundamentally, the kernel Object Manager in Windows has always had namespaces, from the very first Windows NT release, so it's not that strange. – MSalters Apr 04 '16 at 14:08
  • 3
    And with Remote Desktop Services, the Session objects actively use these namespaces to provide concurrent operation. That doesn't mean you have all the required infrastructure, but major parts are there. As for `chroot`, realize that the Ubuntu environment already has a different root than the WIN32 one. – MSalters Apr 04 '16 at 14:13
  • 6
    Actually, I think it's too early to answer this either way. As described in [a comment by Scott Hanselman](http://www.hanselman.com/blog/DevelopersCanRunBashShellAndUsermodeUbuntuLinuxBinariesOnWindows10.aspx#a71f8d4b-d9e6-4a0c-af9b-46ae2f6d60b1), the Windows 10 kernel now accepts Linux syscalls. So the question is whether the syscalls that Docker needs (for chroot and namespaces) were implemented or not. While the answer is likely "no", there is no definitive information either way,as far as I can tell. – sleske Apr 04 '16 at 15:02
  • Also note that there is a [Docker port for FreeBSD](https://wiki.freebsd.org/Docker), so there is a precedent for porting Docker to a different kernel. – sleske Apr 04 '16 at 15:04
  • 1
    @sleske is right, this question isn't answerable at the moment, and saying "no it can't" without any real indication of what the devs working on the linux space in widows are up to is pretty presumptuous. – Ryan Apr 04 '16 at 17:03
  • 2
    I don't know enough to state with confidence that this answer is totally wrong, but the way it is phrased makes me a bit skeptical of its validity. In particular stating "Bash is a simple user space program and cannot provide any of these" and referring to the Window Subsystem for Linux as "the new Bash feature" makes it sound like this answer is based on the totally false assumption that all Microsoft did was port bash to Windows. That's not what happened. They developed a whole Linux kernel interface running on top of the Windows kernel: https://msdn.microsoft.com/en-us/commandline/wsl/about – Ajedi32 Apr 04 '16 at 20:00
  • I added my own answer, so this information is not buried in a comment. – sleske Apr 05 '16 at 07:15
  • *"Bash is a simple user space program"* but it runs in a whole Linux subsystem and has nothing to do with the features provided by it. But still at the moment chroot is not supported. – Sami Kuhmonen Aug 09 '16 at 16:50
13

The first insider preview was released yesterday. I've attempted to install docker but it fails with the following: docker fail

So it would appear, that for the first preview it does not currently work. However as many people have speculated, it may work in a future release.

CodedBeard
  • 249
  • 2
  • 6
  • 5
    Good idea to actually try this. One thing: Could you please add the text of the screenshot as actual text (Ubuntu terminal supports copy&paste). "Real" text has numerous advantages (easier to read, supports screen readers, crawlable by search engines) – sleske Apr 11 '16 at 07:02
  • Some update: I've been able to completely install docker on my machine running the final anniversary update. But doing a `docker ps` fails with: `Get http:///var/run/docker.sock/v1.18/containers/json: dial unix /var/run/docker.sock: setsockopt: invalid argument. Are you trying to connect to a TLS-enabled daemon without TLS?` – kumarharsh Aug 04 '16 at 13:43
  • Looks like it works now: https://tutorials.ubuntu.com/tutorial/tutorial-windows-ubuntu-hyperv-containers?backURL=/#0 – Nick Sweeting Oct 26 '17 at 03:59
7

As of the Creator Update (released publicly on June 13, 2017) you can run native Windows executable directly in WSL. This means if you've already installed Docker for Windows you can simply invoke the docker binaries installed under C:\Program Files. Since they end in .exe the easiest option is to create aliases. Something like the following in your .bashrc should work:

DOCKER_BIN='/mnt/c/Program Files/Docker/Docker/resources/bin'
for f in "$DOCKER_BIN"/*; do
  alias "$(basename "$f" | sed 's/.exe$//')"'="'"$f"'"'
done

This creates aliases for all the files in the DOCKER_BIN directory:

$ type docker
docker is aliased to `"/mnt/c/Program Files/Docker/Docker/resources/bin/docker.exe"'

$ docker --version
Docker version 17.03.1-ce, build c6d412e

One caveat: you'll get an error message like "Unable to translate current working directory" if run from a Linux directory. Just cd into a Windows directory (e.g. /mnt/c/Users/YourUsername) and you should be good.

dimo414
  • 376
  • 1
  • 3
  • 16
  • This does not seem to pick up bash environment variables into docker-compose YML files. Any idea for that? – Rüdiger Schulz Sep 10 '17 at 19:59
  • 1
    That makes sense, since you're invoking the Windows `docker` binary, and just doing so through the Linux shell. I'm not sure if there's a good way to accomplish that. – dimo414 Sep 10 '17 at 21:13
6

Once Docker 1.12 is released and the Linux Docker client is separated, you should be able to run the docker client in Windows 10 bash.

This may not sound like much given you have a Docker Windows client but it's useful if you have Linux toolchains that include docker for it's client-side functionality.

mixja
  • 197
  • 2
  • 7
4

In Windows 10 Version 1607 Build 1493.10 you can successfully install it on Ubuntu Bash, but it doesn't work :(

A simple "docker version" will tell you:

Client version: 1.6.2
Client API version: 1.18
Go version (client): go1.2.1
Git commit (client): 7c8fca2
OS/Arch (client): linux/amd64
FATA[0000] Get http:///var/run/docker.sock/v1.18/version: dial unix /var/run/docker.sock: setsockopt: invalid argument. Are you trying to connect to a TLS-enabled daemon without TLS?

If you then run "sudo docker -d" you get the following error:

FATA[0000] ERROR: You are running Linux kernel version 3.4.0+, which is unsupported for running Docker. Please upgrade your kernel to 3.8+.

So this is definitely a stopper from the bash side.

Nevertheless, you can install Docker for Windows and it works like a charm, you can obviously deploy Linux Servers and everything you need.

> docker version
Client:
 Version:      1.12.0
 API version:  1.24
 Go version:   go1.6.3
 Git commit:   8eab29e
 Built:        Thu Jul 28 21:15:28 2016
 OS/Arch:      windows/amd64

Server:
 Version:      1.12.0
 API version:  1.24
 Go version:   go1.6.3
 Git commit:   8eab29e
 Built:        Thu Jul 28 21:15:28 2016
 OS/Arch:      linux/amd64
Bruno Medina
  • 141
  • 4
3

As of September 2016, No.

All current implementations of Docker on Windows use virtualisation, Docker 1.12 uses a hypervisor in Windows -thus removing the advantage of containerisation over virtualisation.

Docker needs more than just using Linux systems calls.

It needs process control groups (cgroups), a stackable filesystem (aufs), plus other Linux-based systems outside the kernel.

Neither cgroups nor aufs are natively in the Windows 10 kernel.

There is an implementation of Windows Server 2016 here: https://msdn.microsoft.com/en-gb/virtualization/windowscontainers/quick_start/quick_start_windows_server ..but this will only run some Windows services, e.g. IIS, and not Ubuntu

Graham
  • 31
  • 2
2

Docker does not currently work in the current build (14316) - assuming you can get it installed.

root@localhost:~# docker --help
runtime: address space conflict: map(0x7ff5ddbb0000) = 0x7ff5ffd20000
fatal error: runtime: address space conflict
lgj
  • 29
  • 1
1

From: https://blog.docker.com/2016/07/docker-for-mac-and-windows-production-ready/

Faster and more reliable – native development environment using
hypervisors built into each operating system. (No more VirtualBox!)
gavenkoa
  • 712
  • 8
  • 12