If docker uses the underlying linux os, why specify the OS in the FROM line of a Dockerfile
I’ve read that on linux, Docker uses the underlying linux kernal to create containers. So this is an advantage because resources aren’t wasted on creating virtual machines that each contain an OS.
I’m confused, though, as to why most Dockerfiles specify the OS in the FROM line of the Dockerfile. I thought that as it was using the underlying OS, then the OS wouldn’t have to be defined.
I would like to know what actually happens if the OS specified doesn’t match the OS flavour of the machine it’s running on. So if the machine is CentOS but the Dockerfile has
FROM Debian:latest in the first line, is a virtual machine containing a Debian OS actually created.
In other words, does this result in a performance reduction because it needs to create a virtual machine containing the specified OS?
One Solution collect form web for “If docker uses the underlying linux os, why specify the OS in the FROM line of a Dockerfile”
I’m confused, though, as to why most Dockerfiles specify the OS in the
FROM line of the Dockerfile. I thought that as it was using the
underlying OS, then the OS wouldn’t have to be defined.
I think your terminology may be a little confused.
Docker indeed uses the host kernel, because Docker is nothing but a way of isolating processes running on the host (that is, it’s not any sort of virtualization, and it can’t run a different operating system).
However, the filesystem visible inside the container has nothing to do with the host. A Docker container can run programs from any Linux distribution. So if I am on a Fedora 24 Host, I can build a container that uses an Ubuntu 14.04 userspace by starting my Dockerfile with:
Processes running in this container are still running on the host kernel, but there entire userspace comes from the Ubuntu distribution. This isn’t another “operating system” — it’s still the same Linux kernel — but it is a completely separate filesystem.
The fact that my host is running a different kernel version than maybe you would find in an actual Ubuntu 14.04 host is almost irrelevant. There are going to be a few utilities that expect a particular kernel version, but most applications just don’t care as long as the kernel is “recent enough”.
So no, there is no virtualization in Docker. Just various (processes, filesystem, networking, etc) sorts of isolation.