A brief on the Docker image management

As we saw in the previous chapter and earlier in this chapter, there are many ways of getting a handle on a Docker image. You could download a full setup application stack from the public repository using the docker pull subcommand. Otherwise, you could craft your own application stack either manually using the docker commit subcommand or automatically using Dockerfile and the docker build subcommand combination.

The Docker images are positioned as the key building blocks of the containerized applications that in turn enable the realization of distributed applications, which will be deployed on the cloud servers. The Docker images are built in layers, that is, the images can be built on top of other images. The original image is called the parent image and the one that is generated is called the child image. The base image is a bundle, which comprises an application's common dependencies. Each change that is made to the original image is stored as a separate layer. Each time you commit to a Docker image, you will create a new layer on the Docker image and each change that is made to the original image will be stored as a separate layer. As the reusability of the layers is facilitated, making new Docker images becomes simple and fast. You can create a new Docker image by changing a single line in Dockerfile and you do not need to rebuild the whole stack.

Now that you learned about layers in the Docker image, you may be wondering how one could visualize these layers in a Docker image. Well, the docker history subcommand is an excellent and handy tool for visualizing the image layers.

Here, let's see a practical example for understanding layering in the Docker images better. For this purpose, let's follow these steps:

  1. Here, we have Dockerfile with the instructions for automatically building the Apache2 application image on top of the Ubuntu 14.04 base image. The RUN section of the previously crafted and used Dockerfile of this chapter will be reused in this section, as shown here:
      ########################################### 
# Dockerfile to build an Apache2 image
###########################################
# Base image is Ubuntu
FROM ubuntu:14.04
# Author: Dr. Peter
MAINTAINER Dr. Peter <[email protected]>
# Install apache2 package
RUN apt-get update &&
apt-get install -y apache2 &&
apt-get clean
  1. Now, craft an image from the preceding Dockerfile using the docker build subcommand, as shown here:
      $ sudo docker build -t apache2 .
  1. Finally, let's visualize the layers in the Docker image using the docker history subcommand:
      $  sudo docker history apache2

The preceding subcommand will produce a detailed report on each layer of apache2 Docker image, as shown here:

      IMAGE          CREATED       CREATED BY     SIZE
aa83b67feeba 2 minutes ago /bin/sh -c apt-get
update && apt-get inst 35.19 MB
c7877665c770 3 minutes ago /bin/sh -c #(nop)
MAINTAINER Dr. Peter <peter 0 B
9cbaf023786c 6 days ago /bin/sh -c #(nop)
CMD [/bin/bash] 0 B
03db2b23cf03 6 days ago /bin/sh -c apt-get
update && apt-get dist-upg 0 B
8f321fc43180 6 days ago /bin/sh -c sed -i
's/^#s*(deb.*universe)$/ 1.895 kB
6a459d727ebb 6 days ago /bin/sh -c rm -rf
/var/lib/apt/lists/* 0 B
2dcbbf65536c 6 days ago /bin/sh -c echo
'#!/bin/sh' > /usr/sbin/polic 194.5 kB
97fd97495e49 6 days ago /bin/sh -c #(nop)
ADD file:84c5e0e741a0235ef8 192.6 MB
511136ea3c5a 16 months ago 0 B

Here, the apache2 image is made up of ten image layers. The top two layers, that is, the layers with the aa83b67feeba and c7877665c770 image IDs are the result of the RUN and MAINTAINER instructions in our Dockerfile. The remaining eight layers of the image will be pulled from the repository by the FROM instruction in our Dockerfile.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset