Docker for Windows networking

g3cko picture g3cko · Sep 7, 2016 · Viewed 11.5k times · Source

I'm having some trouble understanding Docker for Windows and how the networking works. In VirtualBox with a bridged adapter and an Ubuntu vm, things just worked - I could ping the vm from my host (and vice versa) fine.

  • How do I ping a container from any device on my network?
  • And how do ping other containers not running on the same host?

My plan...

was to have multiple windows machines (not vms) each running a single Docker container (to form a storage cluster), and these containers need to talk to each other (run using overlay network possibly, or does this require swarm?). I also need to talk to this externally, which is the only part I was able to get working, using the docker run -p option to expose the ports in the container I need.

To elaborate my though process a bit more, my goal is to build a Amazon S3 style key value store (specifically, using Riak KV) which runs on linux. Since this would require multiple computers running the software, it seemed to me that Docker could have benefits including, ease of setup and deployment, as well as a framework to run linux based softare on Windows, which is what I currently have easy access to.

Couple things I've tested...

If I run two Ubuntu containers on the same host using the default bridge network, they can ping each other. ifconfig lists a local and eth0 adapter with a 172.17... ip address. From this, it doesn't sound like bridge is what I'm looking for, since I want multiple hosts.

relatively small network on a single host

If I run an Ubuntu container using --network host I get a lot more output from ifconfig including "br-xxxxxxxx" and "vethxxxxxx" adapters. From the docs,

adds a container on the hosts network stack

This sounded useful, but perhaps I'm not understanding. I know Docker for windows runs a MobyLinuxVM, and uses a Hyper-V adapter and switch, what is host referring to? The windows pc or this VM? With --network host, I'm still unable to ping my container or ping my desktop from the container.

Other thoughts...

It seems the common use of Docker is NOT Windows based, so I've not been able to find as much to reference. Is my use case very different from the normal use of Docker? Can anyone point out things I am missing here?

Reading about Hyper-V adapters makes it look like I need to change my network adapter setup in addition to how I launch the containers? I guess, I'm having a hard time understanding where to look between windows, hyper-v adapter/switch, ubuntu, and docker.

Answer

Trevor Sullivan picture Trevor Sullivan · Sep 7, 2016

Great question. I upvoted it to counter the downvote you received. The question is well-written, and I don't see any issues with it. Perhaps they thought it didn't belong on StackOverflow, and was better suited for ServerFault.

Here are a few helpful bullets:

  • Docker for Windows creates a Hyper-V Linux VM named MobyLinuxVM.
  • Hyper-V VMs must be connected to a Virtual Switch in order to have network access
  • Docker for Windows creates a Hyper-V Internal Virtual Switch named DockerNAT
  • Check out What is the Hyper-V Virtual Switch Explained for details about the internal Virtual Switch type (you already linked to this)

Docker Swarm

  • Using the overlay network does indeed require Docker Swarm Mode (see: SwarmKit)

The bottom line here is:

The scenario that you're trying to solve for is not appropriate for Docker for Windows. Docker for Windows is intended to enable software developers to write, debug, and test their applications against a local Linux VM with the Docker Engine installed. That's about it. Docker for Windows automates the process of setting up the Hyper-V VM, installing Linux, installing the Docker Engine, and making it accessible from the command line.

Your proposed scenario under "My Plan" would not be a suitable one for Docker for Windows. Instead, I'd suggest setting up a Docker Swarm Mode cluster. Docker storage gets a bit more complicated than that, though. You'll also want to look into using a Docker storage driver that enables shared storage across your Swarm cluster of Docker Hosts. There's a very popular one called Flocker, developed by ClusterHQ. I'd recommend looking into that as a possible solution.

However, I'd also suggest re-evaluating your goals, and how you accomplish them. Docker might not even be the right solution for generic shared storage.

Hope this helps your efforts.