Search code examples
dockerdockerfiledocker-image

How happens when Linux distributions are different between the docker host and the docker image?


As I understand, a Docker image (and consequently, a container) can be instantiated from different Linux distributions, such as Ubuntu, CentOS and others.

Let's say my Docker host is running standard Ubuntu 14.04.

  • What happens if I use container that is not based on the same Linux distribution?
  • Not 14.04?
  • Not Ubuntu (or any other Debian-based)?
  • What are the disadvantages of using different base-images of images you use? (Let's say I use Image A that uses Ubuntu as a base image, Image B that used Debian as base image and Image C that uses CentOS as base image)?

Bonus question: How can I tell what base image was used for an image if the developer didn't specify it in the Docker Hub description?


Solution

  • Docker does not use LXC (not since Docker 0.9) but libcontainer (now runc), a built-in execution driver which manipulates namespaces, control groups, capabilities, apparmor profiles, network interfaces and firewalling rules – all in a consistent and predictable way, and without depending on LXC or any other userland package.

    A docker image represents a set of files winch will run as a container in their own memory and disk and user space, while accessing the host kernel.
    This differs from a VM, which does not access the host kernel but includes its own hardware/software stack through its hypervisor.
    A container has just to set limits (disk, memory, cpu) in the host. An actual VM has to build an entire new host.

    That docker image (group of files) can be anything, as long as:

    That means an image can be anything: another linux distro, or even a single executable file. Any executable compile in go (https://golang.org/) for instance, could be packaged in its own docker image without any linux distro:

    FROM scratch
    COPY my_go_exe /
    ENTRYPOINT /my_go_exe
    

    scratch is the "empty" image, and a go executable is statically linked, so it is self-contained and only depends on system calls to the kernel.