Windows and Linux Containers simultaneously Windows 10 - docker

I have a solution that includes about 5 containers. Most of them are alpine linux based, but one has to be a windows container. Unfortunately, the windows container relies on one of the linux containers for authentication and must be able to run alongside it. I am trying to set things up so I can develop locally with both containers running at the same time but I am having some trouble. Is it possible to run both Windows and Linux containers simultaneously on a Windows 10 Pro host using Docker for Windows (Hyper-V version)?
Essentially what I am looking for is the equivalent of running a docker compose file with both linux and windows containers in it (although everything I have researched says this isn't possible).

It looks like docker edge version 18.02 has the ability to run windows and linux containers next to each other using LCOW (Linux Containers on Windows). It hasn't made it into docker-compose yet, but I think it will very soon. Can't wait for the stable version to have this!

Related

How can a linux container work on windows without a linux virtual machine (ie: native support)

From what I understand, the container includes all dependencies to run, but all containers running on the same platform whether it's a VM, or bare-metal will share the underlying kernel.
I believe I read somewhere that in order to run linux containers on windows, the Docker client spins up a linux based VM, and runs the container in that.
But now I see that docker for windows runs linux containers natively (ie, without hyper-v).
My question is: How can an image that was built to run on linux run on a system that has a windows kernel?
This is the original source that my question arose from:
https://www.hanselman.com/blog/DockerAndLinuxContainersOnWindowsWithOrWithoutHyperVVirtualMachines.aspx
With the latest version of Windows 10 (or 10 Server) and the beta of
Docker for Windows, there's native Linux Container support on Windows.
That means there's no Virtual Machine or Hyper-V involved (unless you
want), so Linux Containers run on Windows itself using Windows 10's
built in container support.
I saw some similar questions, but they explained how a linux container runs on a windows platform by utilising a vm/hyper-v
How docker desktop runs linux containers on Windows machine
Does "Docker On Windows" launch a linux virtual machine?
Perhaps I didn't understand their answers, but from what I understood, it still seems like the linux container is sitting on-top of the windows kernel.
this is the magic of LCOW (https://github.com/linuxkit/lcow)
you are right to run a container the base KERNEL should be same , since container is just an abstraction , so to run a linux container on windows there are two options
either use moby linux on hyperv and run containers there
use lcow to run light weight linux vm for each container. (lcow)
https://learn.microsoft.com/en-us/virtualization/windowscontainers/deploy-containers/linux-containers
with WSL in windows in future we might be able to get a third method don't know if already someone is working on it .

Why does Docker for Windows make you pick either Windows or Linux containers?

When using Docker for Windows, you must choose to either use Windows or Linux containers, but you can't use both at the same time. What is the technical reason(s) for this? It's a little counter-intuitive, since each container has its own isolated operating system.
Linux containers on Docker for Windows are not handled by windows itself, but they are using Hyper-V Linux VM - MobyLinuxVM. Hence the necessity to switch between Linux and Windows.
However starting from Windows 1709 and Docker in edge version you can try out linux containers on windows - see: https://blog.docker.com/2017/09/docker-windows-server-1709/
Update
As #v.karbovnichy brought up, technically on Docker for Windows you "can" run linux and windows containers simultanously - you can use docker-machine command to create additional linux-based virtual machine that will run your linux containers. Then, you can connect them into one swarm and, with a dose of good will, you will run linux and windows containers simultaneously on same machine.
docker client command itself can connect to both linux or windows docker-server and "manage" both of them - check docker login - it's widely used in server configurations.
However as stated above, true running linux and windows containers next to each other is in preview state.
Docker ecosystem on your Windows machine contains several components.
One is Docker command line: the docker command that you use for everything-management. The second one is Docker daemon - A self-sufficient runtime for containers, the core.
Docker daemons for Linux Containers and Windows Containers are different, but they listen for connections from the docker client on the same pipe. So one needs to be stopped for other to be started. This is the technical reason that you asked for.
However, you can observe that containers started for ex. in MobyLinuxVM is still running and available for connections when you switch to Windows containers. The only thing here is that you cannot manage them because the Docker daemon for Windows does not know how to manage Linux containers in MobyLinuxVM.
UPDATE: As described in this post,
Docker for Windows 18.02 now supports Linux and Windows containers running side-by-side via LCOW, using a single Docker daemon.
So actually now you can use one docker daemon to manage both worlds, it's just about using the new --platform flag in docker pull.

Docker: Why use Linux containers on Windows?

I am using Win 10 Pro N (Version 1709) as a development machine and Windows Server 2016 Standard (Version 1607) as production server.
I am currently developing an ASP.NET Core 2 application with MongoDb as database.
A couple days ago I first stumbled over the idea, to run MongoDb as a Docker image.
I don't have any experience with Docker so far, but I managed to switch from Linux containers (default) to Windows containers on Windows machines.
Was this a good decision? Or is there any reason why I should use Linux containers instead of Windows containers in my scenario?
What e.g. if I should decide to deploy my application to a Linux server some time? In this case, would it wiser to start with Linux containers right from the beginning?
Docker is not about virtualization but more about isolation.
A windows container will run on a windows host
A linux container will run on a linux host
Then some people wanted to run linux container on windows
First you needed to create a linux vm on windows to run the container
Now you can use LinuxKit to run the container but it's still a light VM
Then some people wanted to run windows container on linux
First you needed to create a windows vm on linux to run the container
Now you can use nothing more as of today
So the best bet is to start with a container aimed at your production servers
If you want to deploy to linux I would advise using linux containers since you then test a more similar setup and are more likely to find issues that will also show in your final deployment.
Other than that linux container technology is more mature and better supported than windows containers.

Can a linux app run on windows using Docker?

I am aware of this question (Can Windows Containers be hosted on linux?), but it doesn't really answer my question.
I am new to Docker, but my question is such - if I take any windows application, put it inside a Docker container, can it run now on Linux and vice versa?
Confluent claims that it can run only on linux, but my colleague installed it on Windows using Docker. So if you can install it with Docker, then the whole application would surely be regarded as cross platform?
I think I am missing some important point here.
Docker is not a VM, it's a way to run applications on a shared kernel that isolate those applications from each other. Windows binaries don't run on a Linux kernel, and vice versa (ignoring the Linux runtime for Windows for the time being). So if you build a container with your Windows application, it will only run if you did so on Dockers Windows runtime and windows base image. It's won't run on a Linux host.
What docker does provide is an embedded VM running Linux (originally this was VirtualBox, but current versions are HyperV). By running Docker for Windows, by default, this VM was used and you would only be running Linux containers, so your windows application would not even run inside the container. To run the Windows binaries, you need to toggle Docker for Windows to use the Windows runtime, and presently that's a toggle, you can't run both Linux and Windows runtimes concurrently on the same host.
There also is no Windows VM packaged with Docker's Linux install. You would need to install your own copy of Windows (and get the licensing which is why Docker doesn't ship this) inside a VM on a Linux host and run your containers inside that VM if you need Windows support.

Docker and specifying a target OS

I've read that:
Docker is a system for management and deployment of application containers, not operating system containers.
However, in several resources (e.g. around 1:20 into https://www.youtube.com/watch?v=pGYAg7TMmp0) it gives an example of "problems" you might encounter if you've developed a web application on a Windows PC or Mac, and are deploying it to a Linux server.
So, how does Docker help in this situation? If we take a web application I understand Docker could help you make a container with the source, and say a specific version of PHP. But could you specify a target OS for it to run on, if it's different from the server that Docker is running on?
The Docker FAQ (https://docs.docker.com/engine/faq/) says
You can run both Linux and Windows programs and excutables in Docker containers.
Does this mean you need Docker installed on a Linux and Windows machine separately to do this, or is it possible to specify any OS within your Docker image and have any machine run it?
Please can someone explain how - or if - Docker deals with specifying a particular OS for your application?
Docker started as a way to run containers on Linux hosts, and this remains the dominate target for docker containers. Developer environments include an embedded VM to run Linux under the covers on Mac and Windows. Originally this was VirtualBox, but newer releases use xhyve and hyperv. The host OS in all of these are Linux so you are not building your image on one OS and running it on another OS.
Since that start, Docker has expanded target OS's. This requires that you have a docker installation for that OS, and it requires that your image be designed to run on that architecture/OS. This started with other architectures of Linux like arm64, and now zLinux. The Microsoft partnership is a rather large rewrite, partially in Windows itself, but also in the Docker code, and especially in the images designed to run natively on Windows. To run these, you have to change the settings on Docker for Windows to run Windows containers instead of Linux containers, you cannot run them both concurrently on the same host. At present, running Windows binaries can only be done on a Windows host, Microsoft isn't shipping free VMs for Linux hosts. And as a new target platform, it still lags behind in features from the Linux hosts.

Resources