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.
Related
So I have a use case where I need to detect inside of a WSL2 VM whether the Docker setup is Docker for Windows w/ WSL integration vs Docker just running inside of the WSL VM (say installed directly via apt or dnf). The networking situation between these two use cases is different because with Docker for Windows WSL integration you cannot reach containers by their IP from the WSL VM. This poses some problems for some dev-tooling that we have and wasn't previously an issue with devs running on Linux-native machines but we've recently run into it now that some devs are using Windows machines with WSL and Docker for Windows.
Any thoughts on how I can do this? Look for specific env vars, mount points etc?
Looks like I can just stat /mnt/wsl/docker-desktop and see if that exists.
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 .
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!
Is it possible that I run docker without any host OS. I mean run it natively. It would be a performance boost that way I believe if possible.
Suppose I have a tool which runs on linux kernel. I create a docker container with some extra dependencies. Now I share that container with other person who has linux to run that container.
But I want to run that container without host OS. as it will be double layer of OS with container.
Docker itself is not a VM, so there is no double layer of OS. Docker is a tool to run applications with settings that isolate them from other applications running on the same OS kernel. Docker does include a VM with Docker for Windows and Docker for Mac to run the Linux kernel so you can run Linux containers. There is an option to run native Windows containers with Server 2016, but if you are looking for minimal and efficiency, I would suggest looking elsewhere.
The closest things to what you are looking for are:
Unikernels: these are applications compiled into a kernel with everything else removed, designed to run inside of a VM for a very specialized task, often security related. These are still early in their development stage, but Docker does use some of their technology inside their project.
LinuxKit (part of the Moby Project): this is how Docker creates their VMs for Docker for Windows and Docker for Mac. It is a container based Linux operating system that you can custom compile with only the containers you want to run. Most of the focus of this is still designed for VMs, but bare metal is an option.
Scratch base image: if you statically compile your application to remove all of the library dependencies, you can have a container without any shell or other OS tools. This is often seen in Go binaries shipped as Docker containers to do a single task with a very small attack surface. As a Docker container, it still requires the underlying Linux OS to run the binary.
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.