Is a Docker/LXC container a running app or somethi

2019-02-15 15:24发布

问题:

I just read the excellent SO question asking "What is the difference between Docker and a VM?". However, the accepted answer left me wanting just a wee bit more.

I sort of understand a container (Docker/LXC - I don't get the difference) to use something called libcontainer and AuFS so that dozens, hundreds, even thousands of containers can share the same CPU, RAM and disk resources. But, the answer still doesn't explain exactly what a "container" is!

Is a container just an instance of this libcontainer running? Is it an application that uses libcontainer? Is it something Linuxy like a service/daemon process? So I ask:

  • What exactly is a "container"?
  • What are the exact computing/system resources multiple containers can share inside the same VM/physical?
  • Is Docker/LXC the "hypervisor" in the container equation? If not, what is the relationship between Docker, LXC and libcontainer?

回答1:

the answer still doesn't explain exactly what a "container" is!

A container is basically a process, isolated, with all the environment it needs for its job (a webserver, a database, a CMS, any software...).

A container uses Linux kernel namespaces to isolate process, network and filesystems. A container uses the concept of process isolation: filesystem, process, network, resource (CPU, memory),logging (STDIN...), shell isolation.

Docker/LXC - I don't get the difference

LXC is a set of tools to control containers; Docker is another set of tools (all bundled into the same program), that also adds a file format so the contents of an 'image' can be passed around from machine to machine. Docker is vastly more talked-about than LXC. Docker used to use the lxc library to control containers, but replaced it with its own library called...libcontainer.

What are the exact computing/system resources multiple containers can share inside the same VM/physical?

Containers on the same machine will share CPU, memory and the kernel. Additionally, Docker lets you optionally have them share the same network.

Is Docker/LXC the "hypervisor" in the container equation?

The Linux kernel is the real "hypervisor", and Docker/LXC are sending it commands to create and control containers.