Reputation: 10035
In simple terms, how does a Docker image/container work on another machine that doesn't have an OS?
It seems like with VMs, if you have a machine A with OS A and machine B with OS B and you want to run your code that originated from machine A on machine B, the VM installed on machine B will run OS A so it will work with your code from machine A.
But with Docker, does both machine A and machine B have to have OS A already installed? Or does machine A still have OS A and machine B has nothing and the Docker image/container is run on machine B and creates something similar to OS A in order for it to work on machine B?
Upvotes: 2
Views: 545
Reputation: 1797
Docker still requires a kernel to be running, as images do not provide their own kernel and are not full operating systems.
When the container is started, the layers of the image are joined together to provide everything an app needs to run. The Docker daemon configures various namespaces (process, mount, network, user, IPC, etc.) to isolate the container from other processes on the same machine. That's what provides the look and feel of being a separate VM, even when it's just another process on the machine.
At the end of the day, a container is simply another process running on the machine. It's just one that brought along its entire environment.
I recently wrote a blog post about this in which I made a new image that might be helpful to visualize how it's working. We have the traditional VM stack on the left with the "containerized" version on the right. Again, they're just processes sharing the same kernel, but walled off using kernel namespaces.
Upvotes: 2
Reputation: 1323353
A docker image/container will run on any machine whose kernel is compatible: the container will make only system call to the kernel.
If Machine B (for instance a Windows PC) does not have a Linux OS, it will need a VM in order for a classic Linux container to run.
See also:
Upvotes: 1