gextra
gextra

Reputation: 8905

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

I am running a Docker daemon on my GUEST OS which is CentOS. I want to install software services on top of that in an isolated manner and I do not need another OS image inside my Docker container.

I want to have a Docker container with just the additional binaries and libraries for the software application I am going to install.

Is there a "whiteglove/blank" base image in Docker I can use ? I want a very lean container that uses as a starting point what my GUEST OS has to offer. Is that possible ?

Upvotes: 30

Views: 17989

Answers (5)

bluelights
bluelights

Reputation: 1306

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.

Upvotes: 24

Zon
Zon

Reputation: 19908

Following the links of Rohan Singh, I found some related info, that doesn't generally contradict, but relates to the core ide of the question:

The base image for all Docker images is the scratch image. It has essentially nothing in it. This may sound useless, but you can actually use it to create the smallest possible image for your application, if you can compile your application to a static binary with zero dependencies like you can with Go or C.

Upvotes: 0

Henaras Khazaei
Henaras Khazaei

Reputation: 121

For any container, you need to have at least a root file system. That is why you need to use a base image that have the root file system. Your idea is not completely against the container paradigm of usage; as opposed to VMs, we want container to be minimal without much of repetitive elements that it can leverage from the underlayer OS.

Upvotes: 1

Rohan Singh
Rohan Singh

Reputation: 21535

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.

Upvotes: 37

Reza S
Reza S

Reputation: 9758

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.

Upvotes: 9

Related Questions