I have just started learning dockers and containers. It's make sense to me that I can containerized my application with all its dependencies and deploy it on docker engine and run it. But I am confused how OS such as UBUNTU is being deployed as container on docker? Because the basic concept what I understand is that, docker container is without or minimal OS dependencies for the application. Then why OS is also used as containers? Are the OS being treated as application on docker? or they have some other use and they just provide minimal dependencies for the application? It would be great if someone can explain this concept.
-
1This answer here might be a good read: https://stackoverflow.com/questions/16047306/how-is-docker-different-from-a-virtual-machine?rq=1 – stackErr Feb 19 '19 at 11:44
-
1@stackErr No, I understand the difference between VM and docker. I want to understand why OS still being used as docker, when the basic concept of docker is to have container without OS or minimal dependencies. – Waqar Ahmed Feb 19 '19 at 11:58
2 Answers
Linux systems contain Linux kernel and a set of programs/utilities on top of it, which define the overall behavior and look of the system. What makes Docker lightweight comparing to virtualization technologies is that it shares kernel with host OS. But not the rest of the programs.
You wouldn't probably want to deploy you app on pure kernel - you need POSIX api's together with shell and package manager. All this stuff comes with Ubuntu or whatever distro you prefer. So, containerizing your app you select best fitting Linux distro and use appropriate base docker image. Normally you consider the size, default package manager and rolling/stable deployment rules.
In fact, you can create your image with LFS
or minimal code using FROM scratch
directive, but I doubt this worth spent time.
So, returning to your questions:
But I am confused how OS such as UBUNTU is being deployed as container on docker?
Just mounted as a tar.gz rootfs
Then why OS is also used as containers?
To let you have package manager, glibc and other stuff. You like RUN apt-get install -y whatever
, don't you?
Are the OS being treated as application on docker?
No, there is no application concept in Docker. Only main process, which keeps container alive. And OS is NOT treated as main process.

- 8,185
- 1
- 19
- 31
-
Hi Thanks for the answer. Does it mean that if I am using windows to build application I will use base window docker and if linux then base linux docker? which will provide me the minimal amount of libraries to run my application? The other question, if app still needs the basic functionalities from any base OS distro docker then what does it mean to share the kernel with host OS? – Waqar Ahmed Feb 19 '19 at 13:01
-
No, Windows (as well as MacOs) cant share linux kernel (obviously because they dont have it), and on these systems Docker is not lightweight and implemented using virtualization (for Windows it is HyperV or VirtualBox on your choice). – grapes Feb 19 '19 at 13:05
-
ah ok. So if I am developing my app on linux and run my docker on linux as well then I don't need to use base OS docker? because it will share the host kernel. – Waqar Ahmed Feb 19 '19 at 13:10
-
Again no) If you app is for Linux and is dockerized, you can run it on any OS which supports Docker. For your app it will be transparent. But when run on Linux host machine, you would probably expect better performance. But again - for your app that brings no changes, it anyway runs in selected distro, regardless of what is the host machine's OS – grapes Feb 19 '19 at 13:26
-
Thanks again for clearing it. It makes much more sense now. So app can run without the base OS docker image as well? In which situation it will make sense to have or without the base OS in the docker? – Waqar Ahmed Feb 19 '19 at 13:30
-
I think I got it. Because all linux distro shares the same kernel but they have different utilities let's say ubuntu use apt-get where as centos use yum. And If Im running ubuntu as host OS and in docker I use centos, I would be able to run yum inside the docker? and this base OS docker, will have only centos utilities because centos and ubuntu have the same kernel. is it? – Waqar Ahmed Feb 19 '19 at 13:37
Docker will provide bare minimum version of os to deploy your application. Like if you use alpine(smallest image in docker), its around 5 MB size. You have to manually install other component specific to your application. Docker will provide you the platform to create a container. Inside the container its your wish what you want to use. You may use alpine or any advanced os like ubuntu then you can deploy your application.

- 46
- 3
-
So does it means that there is still OS involved in containers? Can I have an app on docker without any base OS in it? how it would be different from the app container which have an OS in it? – Waqar Ahmed Feb 19 '19 at 13:16