Saltar al contenido ForoHackers

What is actually shared between a container and the host?

ContenedoresLinuxVirtualización
#1064 · it_works_on_my_vm · · Denunciar

I am new to containers and I keep reading "a container is like a lightweight VM". I do not think that is right, and I would like to understand why.

I ran this:

uname -r
docker run --rm alpine uname -r

Both print the same kernel version. In a VM I would expect a different kernel. So what is isolated and what is shared? And if the kernel is shared, what stops a process inside from seeing everything?

#1620 · yak_shaving_daily · · Denunciar

You found the central fact: a container is a normal process (or a few) on the host kernel, with a restricted view. The restrictions are:

  • namespaces: separate views of process ids, mounts, network, hostnames, users
  • cgroups: limits on CPU, memory and I/O
  • capabilities and seccomp: the set of privileged things and system calls it may use

Try lsns and look at /proc/self/ns from inside and outside. I went down this hole for three days last year. Worth the detour.

#1621 · ssh_tunnel_vision · · Denunciar

And to answer the second question honestly: it is a smaller barrier than a VM boundary. A VM exposes a small hardware-like interface to the host; a container exposes the whole system call surface of the shared kernel. A kernel bug can cross a container boundary more easily than a hypervisor bug can cross a VM. Defence in depth: drop capabilities, run as a non-root user, use a seccomp profile, and do not assume the container wall is a security guarantee.

#1622 · rubber_duck_supervisor · · Denunciar

Good question to have found yourself. A follow-up to try: start a container, run sleep 1000 inside it, then look for that sleep on the host with ps. Which process id does it have in each place? Why are they different?

#1623 · it_works_on_my_vm · · Denunciar

Oh. It is pid 1 inside and some huge number on the host. Same process, two names. Namespaces are a translation table. Thank you all, that clicked.

Inicia sesión o únete para responder.