2

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?

stackjlei
  • 9,485
  • 18
  • 65
  • 113

2 Answers2

2

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.

Containers vs VMs

mikesir87
  • 1,785
  • 1
  • 20
  • 25
1

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:

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • what does the docker engine do on machine B vs. on machine A? – stackjlei May 12 '17 at 05:09
  • 1
    @stackjlei The same as on machine A: it runs the container, by isolating the necessary resources from the OS to dedicate them to said container. – VonC May 12 '17 at 05:19
  • so docker needs to be installed on both machines and usually machine A will be used to create the image and then push it up to docker hub and then machine b will be used to pull the image and then run it as a container? – stackjlei May 12 '17 at 05:28
  • 1
    @stackjlei Yes, or you can copy the Dockerfile (a small text file) from A to B, and `docker build` that Dockerfile on machine B: you would get the same image. – VonC May 12 '17 at 09:15