I went through lots of Q&A in StackOverflow and other forums but still didn't clarify why we need a base image as docker doesn't need a new OS to run. It uses the host OS to perform docker operations. Can anybody explain why we need a base image and what's exactly it is?
Related
Main purpose of Docker container is to avoid carrying guest OS in every container, as shown below.
As mentioned here, The FROM instruction initializes a new build stage and sets the Base Image for subsequent instructions. As such, a valid Dockerfile must start with a FROM instruction.
My understanding is, FROM <image> allow a container to run on its own OS.
Why a valid Docker file must have FROM instruction?
Containers don't run a full OS, they share the kernel of the host OS (typically, the Linux kernel). That's the "Host Operating System" box in your right image.
They do provide what's called "user space isolation" though - roughly speaking, this means that every container manages its own copy of the part of the OS which runs in user mode- typically, that's a Linux distribution such as Ubuntu. In your right image, that would be contained in the "Bins/Libs" box.
You can leave out the FROM line in your Dockerfile, or use FROM scratch, to create a blank base image, then add all the user mode pieces on top of a blank kernel yourself.
Another common use of FROM is to chain builds together to form a multi-stage build of smaller images.
This would be useful for instance to limit redundant rebuilding during failed auto-builds.
FROM instruction specifies the underlying OS architecture that you are gonna use to build the image. You have to use some form of base image for you to get started with building an image. It can be ubuntu, centos or any minimal linux image like ALPINE which is only 5MB!. The idea is to install only the packages you need rather than having everything bundled and packaged as a distribution. This makes the size of the docker images very small as compared to the full blown OS distribution. I hope this answers your question. Let me know if you have any questions.
I am using Windows OS but to use docker I use CentOS VM over Oracle VM Virtualbox. I have seen a Dockerfile where centos is used as base image. First line of my Dockerfile is
FROM centos
If I check the Dockerfile of CentOS on Docker Hub then first line is
FROM scratch
scratch is used to build an explicitly empty image, especially for building images. Here I can understand that if I start traversing upward using "FROM " line then finally I will end up at "scratch" image. I can see that scratch can be used to create a minimal container.
Question: If I want to create some bigger applications using web server, database etc, then is it necessary to add a base OS image?
I have tried to search for mysql and tomcat and noticed that it finally uses a OS image.
My understanding of Container was that I can "just bundle the required software and my service" in the container. Please clarify.
Your understanding is correct, however "just bundle the required software and my service" may be cumbersome, especially if you also have some shell scripts that make further use of other support programs.
Using some base image that contains already all the necessary stuff is more convenient. You can share the same base image for several services and due to docker's layered images will have no overhead regarding disk space.
I have a software package running on RHEL5.4
Can I make a docker image of my software which can run on user machine with RHEL6.5?
Some comments first
You may already know that but just in case: a container should not be seen as a Virtual Machine. This is more like an isolation for an application.
I wanted to start with this remark because your container won't exactly be a RHEL. You have to start with a simple and minimal base, identify the libraries you really need and try to build the smallest possible image like that.
Last remark (it was not clear from your question) your host might be an OS and your container might be another OS. (you can run Ubuntu containers on a Windows host for example)
CentOS
You might want to look at CentOS: https://hub.docker.com/_/centos/
CentOS is really close to a Red Hat in terms of libraries and packages. I would then recommend to start from a CentOS image.
I hope it helps
I am very new to Docker and currently trying to get my head around if there is any best practice guide to update software that runs inside a docker container in a very large distributed environment. I already found couple of posts around updating a MySQL database in docker, etc. It gives a good hint for any software that stores data, but what if you want to update other parts or your own software package or services that are distributed and used by several other docker images through docker-compose?
Is there someone with real life experience doing that in such an environment who can help me or other newbies to understand the best practices in docker if there are any.
Thanks for your help!
You never update software in a running container. You pull down a new version from the hub. If we assume you're using the latest tag (which is a bad idea, always pin your versions) of your image and it's one of the official library images or the publicly available that uses automated builds you'll get the latest version of the container image when you pull the image.
This assume you've also separated the data out of your container either as a host volume or using the data container pattern.
The container should be considered immutable, if you change it's state it's no longer a true version of the image.
Is there a windows server base image for docker? I'm using boot2docker and I understand it runs an in memory VM based on Tiny Core Linux. All the docker files I see on docker hub have a Linux base image e.g. FROM debian:wheezy. I obviously haven't look at all of them.
Does anyone know if a windows server base image exists or is in the works?
That's, for now, impossible because Mircosoft is willing to implement a docker like behavior but is far away to be launching features like that.
see http://blog.docker.com/2014/10/docker-microsoft-partner-distributed-applications/