Search code examples
docker

Why do you need a base image with Docker?


I have went through every single page of the documentation of Docker.

I do not understand, yet still, why a "base image" (for example, the Ubuntu Base Image) is necessary to furnish the containers before installing/creating an application environment.

My questions:

  • What is a base image and why is it required?
  • Why is it not possible to just to create a container and put the application in it similar to virtualenv of Python?

Solution

  • In fact, Docker works through application of layers that are added to the base image. As you have to maintain coherence between all these layers, you cannot base your first image on a moving target (i.e. your writable file-system). So, you need a read-only image that will stay forever the same.

    Here is an excerpt of the (old) documentation of Docker about the images:

    Since Docker uses a Union File System, the processes think the whole file system is mounted read-write. But all the changes go to the top-most writable layer, and underneath, the original file in the read-only image is unchanged. Since images don’t change, images do not have state.

    But, you can find more explanations on the page 'Understanding the image layers' of the 'Get Started' tutorial from the Docker team.

    Image with layers