Base image with specific operating system base image - docker

when running a base image in Docker file of ubuntu or windows or any other operating system,
for example:
"ubuntu:latest"
do I have to run/build the docker application on a machine with the same operating system corresponding to the operating system in the base image?

No. The only restrictions like that is that Linux images have to run on a Linux host and Windows images have to run on a Windows host.
You can run Alpine, Debian and Ubuntu images on the same Linux host. The thing to have in mind is that the image doesn't contain a Linux kernel, so if you run an Alpine image on a Debian host, your container is running on Debian.
When an image is called Alpine or Debian, that refers to the binaries and libraries that are included. The kernel is shared among containers and is the host's kernel.

Related

Is Docker using my own system's kernel or base image's kernel?

Let's say I've configured and changed a few things in the kernel of my own Ubuntu 16.04. Then I've created a Docker container based on an Ubuntu 14.04. So is this container using the kernel of modified 16.04 or kernel of a clean 14.04?
There is no kernel in a Docker image. This is the fundamental and most important difference between a virtual machine and a Docker container.
The images namedas operating systems distributions such as ubuntu, debian, ... are not operating systems, but are rather images with filesystem structure and tools that you typicaly find in an ubuntu distribution
for example.
So in short, the docker container always uses the kernel of the host machine where it is running.

Create Docker image to run web application in tomcat but without os

I want to create a new Docker image to run our Java based web application in Tomcat.
But till now what I found is that most of the default images comes with inbuild OS (e.g. Ubuntu/Debian etc...).
So here are my question:
1. Can we create an image which will have JRE and Tomcat with our app and no OS?
Because, if I run this image in VM, then VM will have its own OS and again in container there is another OS.
So that's the use of having containers with OS?
The docker images for Ubuntu, Debian ... are not operating systems. They don't have a linux kernel. They are just images having file structure and tools similar to an Ubuntu, Debian OS distribution.
The container does not have it own kernel, it uses the host's kernel where the container is running. This is the fundamental differnece between a virtual machine and a container.

How docker container use host OS?

In every docker tutorial, one of the main advantages of the docker is that docker container use host OS. But if that is true, I don't understand why I need to include OS in the image. For example here is image of centOS. I understand that if I want to run centOS in container I must pull this image but where then host OS come? It would be best if someone can point me to some link to read about that because I cannot find appropriate one.
What Docker uses of the host is actually only the OS's kernel.
What you include in the Docker container is not the actual OS (i.e., the kernel), but rather all the files that make up a specific distribution, such as Ubuntu or Fedora, or whatever…
This is also the reason why you can't run Linux containers on Windows and vice-versa (without a VM), because Linux software of course doesn't work with the Windows kernel, and Windows software doesn't work with the Linux kernel.
So, all Docker containers running on a given host share the host OS's kernel.
It actually shares the kernel & required libraries to boot the image from host OS. That's why those images are really small & not like traditional ISO files. It primarily utilizes union file system, cgroups and namespaces to manage the images and containers.
You can give a quick read to below -
https://kjanshair.github.io/2017/07/04/Docker-Containers-vs-System-Processes/
How is Docker different from a normal virtual machine?

Is it proper to run a Docker image on a host with a different system?

E.g. run a Ubuntu image on a CentOS host, or vice versa. Can I get a real Ubuntu environment inside the image even on a CentOS host?
Ubuntu image on a CentOS host, or vice versa
Yes, as long as the kernel is recent enough to support docker.
The container does not see the OS and its dynamic libraries, it only depends on system call to the kernel.
Can I get a real Ubuntu environment inside the image even on a CentOS host?
"real"? Generally, it is a trimmed version of Ubuntu, without the X11 layer.
But other than that, yes.

Run Different Linux OS in Docker Container?

Have been trying to learn Docker and one thing that puzzles me is how a different flavour of Linux (to the host OS) actually runs in the Docker container.
If we assume my Docker host is running RedHat and I start a container from an Ubuntu image then are the following true?:
logically speaking, if the Ubuntu image footprint is around 550MB then will the Docker Daemon actually download (from an image registry) 550MB worth of Ubuntu image in order to create the Container?
is the instance of Ubuntu running in the container essentially no different than if I had downloaded and installed the same version manually?
I'm aware that the Docker container shares the same kernel used by the host OS and that one of the fundamental points of Docker was its efficiency gains of the container using the underlying OS. So Im a bit confused about what actually happens when you start a Container created from a different Linux version than the host.
I think this previous post may help you understand it a little more - Docker container isolation, does it care about underlying Linux OS?.
The crux of the matter is that if the Host OS is RedHat then it is the RedHat kernel which will be used by whatever build of Linux you run in your Docker container ie. Ubuntu in your example.
This comes down to understanding what the difference is between a Linux OS and a Linux Image. You will not be running a full Ubuntu OS inside the Docker Container but an image of Ubuntu.
For the purpose of your question think:-
OS = kernel + filesystem/libraries
Image = filesystem/libraries
The Ubuntu image running inside your Docker container is just the Ubuntu filesystem/libraries - it will not contain the Ubuntu kernel. This partly explains the efficiencies you get from a Docker container which is leveraging the Kernel (among other things) of the underlying Host.
The Ubuntu image running inside the Docker container runs in what is called the user space for that container. This image can make kernel system calls to the RedHat host OS kernel (as part of transferring control from user space to kernel space for some user operations). Since the core kernel is common technology, the system calls are expected to be compatible even when the call is made from an Ubuntu user space code to a Redhat kernel code. This compatibility make it possible to share the kernel across containers which may all have different base OS images.

Resources