Which Docker base image should be used to install Apps in a container without any additional OS?

What you're asking for isn't possible out-of-the-box with Docker. Each Docker image has its own root filesystem, which needs to have some sort of OS installed.

Your options are:

  1. Use a minimal base image, such as the BusyBox image. This will give you the absolute minimum you need to get a container running.

  2. Use the CentOS base image, in which case your container will be running the same or very similar OS.

The reason Docker images are like this is because they're meant to be portable. Any Docker image is meant to run anywhere Docker is running, regardless of the operating system. This means that the Docker image must contain an entire root filesystem and OS installation.

What you can do if you need stuff from the host OS is share a directory using Docker volumes. However, this is generally meant to be used for mounting data directories, and it still necessitates the Docker image having an OS.


That said, if you have a statically-linked binary that has absolutely no dependencies, it becomes easy to create a very minimal image. This is called a "microcontainer", and Go in particular is well-suited to producing these. Here is some further reading on microcontainers and how to produce them.


One other option you could look into if all you want is the resource management part of containers is using lxc-execute, as described in this answer. But you lose out on all the other nice Docker features as well. Unfortunately, what you're trying to do is just not what Docker is built for.


As I understood docker, when you use a base image, you really do not install an additional OS.

Its just a directory structure sort of thing with preinstalled programs or we can say a file system of an actual base image OS.

In most cases [click this link for the exception], docker itself [the docker engine] runs on a linux VM when used on mac and windows.

If you are confused with virtualization, there is no virtualization inside Docker Container. Containers run in user space on top of the host operating system's kernel. So, the containers and the host OS would share the same kernel.

So, to sumarize:

  1. Consider the host OS to be windows or mac.
  2. Docker when installed, is inside a linux VM running on these host OS.[use this resource for more info]
  3. The base linux images inside the docker container then use this linux VM machine as host OS and not the native windows or mac.
  4. On linux, The base linux images inside the docker container direclty uses the host OS which is linux itself without any virtualization.
  5. The base image inside Docker Container is just the snapshot of that linux distributions programs and tool.
  6. The base image make use of the host kernel (which in all three cases, is linux).
  7. Hence, there is no virtualisation inside a container but docker can use a single parent linux virtual machine to run itself [the docker engine] inside it.

Conclusion: When you install a base image inside docker, there is no additional OS that is installed inside the container but just the copy of filesystem with minimal programs and tools is created.


From Docker's best practices:

Whenever possible, use current Official Repositories as the basis for your image. We recommend the Debian image since it’s very tightly controlled and kept extremely minimal (currently under 100 mb), while still being a full distribution.

What you're asking for is completely against the idea of using Docker Containers. You don't want to have any dependability on your GUEST OS. If you do your Docker wont be portable.

When you create a container, you want it to run on any machine that runs Docker. Be it CentoOS, Ubuntu, Mac, or Microsoft Azure :)

Ideally there are no advantages of your base container OS having to do anything with your Host OS.

Tags:

Docker